From 963f25df8688ca4714404daeadddff37457b9190 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 31 Jul 2024 12:05:56 +0200 Subject: [PATCH] feat(oidc-mock-provider): allow custom overrides for ID token MONGOSH-1843 (#429) --- packages/oidc-mock-provider/src/index.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/oidc-mock-provider/src/index.ts b/packages/oidc-mock-provider/src/index.ts index accffd1..a8e9886 100644 --- a/packages/oidc-mock-provider/src/index.ts +++ b/packages/oidc-mock-provider/src/index.ts @@ -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; + customIdTokenPayload?: Record; skipIdToken?: boolean; }>; @@ -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 = { @@ -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, + }), }; }