Skip to content

Commit

Permalink
feat(oidc-mock-provider): allow custom overrides for ID token MONGOSH…
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax authored Jul 31, 2024
1 parent 89055e3 commit 963f25d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/oidc-mock-provider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ export interface OIDCMockProviderConfig {
* This should include e.g. `sub` and any other OIDC claims that are relevant.
*
* skipIdToken: Exclude ID Token
*
* customIdTokenPayload: Custom overrides in payload data for the ID token
*/
getTokenPayload(metadata: TokenMetadata): MaybePromise<{
expires_in: number;
payload: Record<string, unknown>;
customIdTokenPayload?: Record<string, unknown>;
skipIdToken?: boolean;
}>;

Expand Down Expand Up @@ -325,7 +328,7 @@ export class OIDCMockProvider {
access_token: string;
id_token: string | undefined;
}> {
const { expires_in, payload, skipIdToken } =
const { expires_in, payload, skipIdToken, customIdTokenPayload } =
await this.config.getTokenPayload(metadata);
const currentTimeInSeconds = Math.floor(Date.now() / 1000);
const header = {
Expand Down Expand Up @@ -360,7 +363,11 @@ export class OIDCMockProvider {
// In an ID Token, aud === client_id, in an Access Token, not necessarily
id_token: skipIdToken
? undefined
: makeToken({ ...fullPayload, aud: metadata.client_id }),
: makeToken({
...fullPayload,
aud: metadata.client_id,
...customIdTokenPayload,
}),
};
}

Expand Down

0 comments on commit 963f25d

Please sign in to comment.