Token answers: an expires_in beyond a year is unusable, so the default lifetime applies
A value like 3e11 overflowed the Date the expiry is stored as and surfaced as an untyped error. usableExpiresIn now caps a usable value at 365 days; the refresh path is pinned on memory and live Postgres. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e1ac84fb70
commit
09ea233592
2 changed files with 30 additions and 4 deletions
13
src/oauth.ts
13
src/oauth.ts
|
|
@ -228,10 +228,19 @@ export async function requestProviderTokens(
|
|||
return tokenSet;
|
||||
}
|
||||
|
||||
/** A positive finite number, or a string that is a positive integer. */
|
||||
/** The longest access token lifetime taken at its word: a year. Anything above is not a lifetime. */
|
||||
const MAX_USABLE_EXPIRES_IN_SECONDS = 365 * 24 * 60 * 60;
|
||||
|
||||
/**
|
||||
* A positive finite number of seconds, or a string that is a positive integer,
|
||||
* no longer than a year. A larger value would overflow the Date the expiry is
|
||||
* stored as, so it is unusable and the descriptor's default lifetime applies.
|
||||
*/
|
||||
function usableExpiresIn(value: unknown): number | undefined {
|
||||
const seconds = typeof value === "string" && /^\s*\d+\s*$/.test(value) ? Number(value) : value;
|
||||
return typeof seconds === "number" && Number.isFinite(seconds) && seconds > 0 ? seconds : undefined;
|
||||
return typeof seconds === "number" && Number.isFinite(seconds) && seconds > 0 && seconds <= MAX_USABLE_EXPIRES_IN_SECONDS
|
||||
? seconds
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function sharedRuntimeExchange(provider: Provider): OAuthProviderRuntime["exchangeAuthorizationCode"] {
|
||||
|
|
|
|||
Loading…
Reference in a new issue