diff --git a/.changeset/session-minter-sdk-params.md b/.changeset/session-minter-sdk-params.md new file mode 100644 index 00000000000..29dc8b78d96 --- /dev/null +++ b/.changeset/session-minter-sdk-params.md @@ -0,0 +1,6 @@ +--- +'@clerk/shared': patch +'@clerk/clerk-js': patch +--- + +Add `oiat` field to `JwtHeader` type. Send previous session token and `force_origin` param on `/tokens` requests to support Session Minter edge token minting. diff --git a/packages/clerk-js/src/core/resources/Session.ts b/packages/clerk-js/src/core/resources/Session.ts index ea5e796dbb8..35ff24f7e7c 100644 --- a/packages/clerk-js/src/core/resources/Session.ts +++ b/packages/clerk-js/src/core/resources/Session.ts @@ -480,10 +480,19 @@ export class Session extends BaseResource implements SessionResource { ): Promise { const path = template ? `${this.path()}/tokens/${template}` : `${this.path()}/tokens`; // TODO: update template endpoint to accept organizationId - const params: Record = template ? {} : { organizationId: organizationId ?? null }; + const params: Record = template + ? {} + : { + organizationId: organizationId ?? null, + ...(this.lastActiveToken ? { token: this.lastActiveToken.getRawString() } : {}), + }; const lastActiveToken = this.lastActiveToken?.getRawString(); - const tokenResolver = Token.create(path, params, skipCache ? { debug: 'skip_cache' } : undefined).catch(e => { + const tokenResolver = Token.create( + path, + params, + skipCache ? { debug: 'skip_cache', force_origin: 'true' } : undefined, + ).catch(e => { if (MissingExpiredTokenError.is(e) && lastActiveToken) { return Token.create(path, { ...params }, { expired_token: lastActiveToken }); } diff --git a/packages/shared/src/types/jwtv2.ts b/packages/shared/src/types/jwtv2.ts index f03d6738333..1d8af24d979 100644 --- a/packages/shared/src/types/jwtv2.ts +++ b/packages/shared/src/types/jwtv2.ts @@ -25,6 +25,8 @@ export interface JwtHeader { 'x5t#S256'?: string; x5t?: string; x5c?: string | string[]; + /** @internal - used by Session Minter for monotonic token freshness checks. Do not depend on this field. */ + oiat?: number; } declare global {