Skip to content

Commit 963f25d

Browse files
authored
feat(oidc-mock-provider): allow custom overrides for ID token MONGOSH-1843 (#429)
1 parent 89055e3 commit 963f25d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/oidc-mock-provider/src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ export interface OIDCMockProviderConfig {
3434
* This should include e.g. `sub` and any other OIDC claims that are relevant.
3535
*
3636
* skipIdToken: Exclude ID Token
37+
*
38+
* customIdTokenPayload: Custom overrides in payload data for the ID token
3739
*/
3840
getTokenPayload(metadata: TokenMetadata): MaybePromise<{
3941
expires_in: number;
4042
payload: Record<string, unknown>;
43+
customIdTokenPayload?: Record<string, unknown>;
4144
skipIdToken?: boolean;
4245
}>;
4346

@@ -325,7 +328,7 @@ export class OIDCMockProvider {
325328
access_token: string;
326329
id_token: string | undefined;
327330
}> {
328-
const { expires_in, payload, skipIdToken } =
331+
const { expires_in, payload, skipIdToken, customIdTokenPayload } =
329332
await this.config.getTokenPayload(metadata);
330333
const currentTimeInSeconds = Math.floor(Date.now() / 1000);
331334
const header = {
@@ -360,7 +363,11 @@ export class OIDCMockProvider {
360363
// In an ID Token, aud === client_id, in an Access Token, not necessarily
361364
id_token: skipIdToken
362365
? undefined
363-
: makeToken({ ...fullPayload, aud: metadata.client_id }),
366+
: makeToken({
367+
...fullPayload,
368+
aud: metadata.client_id,
369+
...customIdTokenPayload,
370+
}),
364371
};
365372
}
366373

0 commit comments

Comments
 (0)