Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/session-minter-sdk-params.md
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 11 additions & 2 deletions packages/clerk-js/src/core/resources/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,19 @@ export class Session extends BaseResource implements SessionResource {
): Promise<TokenResource> {
const path = template ? `${this.path()}/tokens/${template}` : `${this.path()}/tokens`;
// TODO: update template endpoint to accept organizationId
const params: Record<string, string | null> = template ? {} : { organizationId: organizationId ?? null };
const params: Record<string, string | null> = 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 });
}
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/src/types/jwtv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading