Skip to content

Commit 0ba2f80

Browse files
committed
fix download authgorizer cis2
1 parent 0d712d4 commit 0ba2f80

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lambdas/download-authorizer/src/__tests__/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('download authorizer handler', () => {
6868
});
6969

7070
const uri = `/${subject}/template-id/proof1.pdf`;
71-
const cookie = `CognitoIdentityServiceProvider.${userPoolClientId}.${subject}.accessToken=jwt`;
71+
const cookie = `CognitoIdentityServiceProvider.${userPoolClientId}.CIS2_555328794105.accessToken=jwt`;
7272

7373
const event = mock<CloudFrontRequestEvent>(makeEvent(uri, cookie));
7474

@@ -89,7 +89,7 @@ describe('download authorizer handler', () => {
8989
test('returns denial if cognito configuration is not present in custom headers', async () => {
9090
const uri = '/subject/template-id/proof1.pdf';
9191
const cookie =
92-
'CognitoIdentityServiceProvider.user-pool-client-id.subject.accessToken=jwt';
92+
'CognitoIdentityServiceProvider.user-pool-client-id.CIS2-int_555328794105.accessToken=jwt';
9393

9494
const event = mock<CloudFrontRequestEvent>(
9595
makeEvent(uri, cookie, {
@@ -122,7 +122,7 @@ describe('download authorizer handler', () => {
122122

123123
test('returns denial if authorization fails', async () => {
124124
const uri = '/subject/template-id/proof1.pdf';
125-
const cookie = `CognitoIdentityServiceProvider.${userPoolClientId}.subject.accessToken=jwt`;
125+
const cookie = `CognitoIdentityServiceProvider.${userPoolClientId}.CIS2-int_555328794105.accessToken=jwt`;
126126

127127
lambdaCognitoAuthorizer.authorize.mockResolvedValue({
128128
success: false,

lambdas/download-authorizer/src/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,19 @@ export function parseRequest(request: CloudFrontRequest) {
2121
const userPoolId = customHeaders?.['x-user-pool-id']?.[0]?.value;
2222
const userPoolClientId = customHeaders?.['x-user-pool-client-id']?.[0]?.value;
2323

24-
const accessTokenKey = `CognitoIdentityServiceProvider.${userPoolClientId}.${ownerPathComponent}.accessToken`;
25-
2624
const cookies = parseCookie(request.headers.cookie?.[0]?.value ?? '');
27-
const authorizationToken = cookies[accessTokenKey];
25+
26+
const authorizationTokenEntry = Object.entries(cookies).find(([k]) => {
27+
const [serviceKey, userPoolClientIdKey, , credentialType] = k.split('.');
28+
29+
return (
30+
serviceKey === 'CognitoIdentityServiceProvider' &&
31+
userPoolClientIdKey === userPoolClientId &&
32+
credentialType === 'accessToken'
33+
);
34+
});
35+
36+
const authorizationToken = authorizationTokenEntry?.[1];
2837

2938
return {
3039
userPoolId,

0 commit comments

Comments
 (0)