Skip to content

Commit 4691055

Browse files
committed
pre-token refactor
1 parent de1b156 commit 4691055

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

lambdas/cognito-triggers/src/pre-token-generation.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,39 @@ export class PreTokenGenerationLambda {
2424
const clientId = event.request.userAttributes['custom:sbx:client_id'];
2525

2626
if (clientId) {
27-
response = PreTokenGenerationLambda.setTokenClaims(event, 'accessToken', {
28-
'nhs-notify:client-id': clientId,
29-
});
27+
response = PreTokenGenerationLambda.setTokenClaims(
28+
event,
29+
'accessTokenGeneration',
30+
{
31+
'nhs-notify:client-id': clientId,
32+
}
33+
);
3034

31-
response = PreTokenGenerationLambda.setTokenClaims(event, 'idToken', {
32-
'nhs-notify:client-id': clientId,
33-
});
35+
response = PreTokenGenerationLambda.setTokenClaims(
36+
event,
37+
'idTokenGeneration',
38+
{
39+
'nhs-notify:client-id': clientId,
40+
}
41+
);
3442
}
3543

3644
return response;
3745
};
3846

3947
private static setTokenClaims(
4048
event: PreTokenGenerationV2Event,
41-
token: 'accessToken' | 'idToken',
49+
tokenKey: 'accessTokenGeneration' | 'idTokenGeneration',
4250
claim: Record<string, string>
4351
): PreTokenGenerationV2Event {
4452
const e = { ...event };
4553

46-
const key = `${token}Generation` as const;
47-
4854
const tokenGeneration =
49-
e.response.claimsAndScopeOverrideDetails?.[key] || {}; // eslint-disable-line security/detect-object-injection
55+
e.response.claimsAndScopeOverrideDetails?.[tokenKey] || {}; // eslint-disable-line security/detect-object-injection
5056

5157
e.response.claimsAndScopeOverrideDetails = {
5258
...e.response.claimsAndScopeOverrideDetails,
53-
[key]: {
59+
[tokenKey]: {
5460
...tokenGeneration,
5561
claimsToAddOrOverride: {
5662
...tokenGeneration.claimsToAddOrOverride,

0 commit comments

Comments
 (0)