mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-08-24 04:13:59 +02:00
Fall back to JWT exp claim when OAuth token response has no expires_in (#506)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import type { Context } from "@yaakapp/api";
|
||||
import { jwtExpiresAt } from "./util";
|
||||
|
||||
export async function storeToken(
|
||||
ctx: Context,
|
||||
@@ -11,7 +12,10 @@ export async function storeToken(
|
||||
throw new Error(`${tokenName} not found in response ${Object.keys(response).join(", ")}`);
|
||||
}
|
||||
|
||||
const expiresAt = response.expires_in ? Date.now() + response.expires_in * 1000 : null;
|
||||
// Prefer expires_in from the response, falling back to the JWT's own exp claim
|
||||
const expiresAt = response.expires_in
|
||||
? Date.now() + response.expires_in * 1000
|
||||
: jwtExpiresAt(response[tokenName]);
|
||||
const token: AccessToken = {
|
||||
response,
|
||||
expiresAt,
|
||||
|
||||
Reference in New Issue
Block a user