From 5b82612910a86c38c2a9ab2229c627b4eaf090c0 Mon Sep 17 00:00:00 2001 From: Rishi Date: Sat, 30 Sep 2023 03:32:27 +0100 Subject: [PATCH] fix: LambdaProxyIntegrationEventV2 authorizer context (#1630) --- .../http/lambda-events/LambdaProxyIntegrationEventV2.js | 5 ++++- .../authenticationCustomVariable.test.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/events/http/lambda-events/LambdaProxyIntegrationEventV2.js b/src/events/http/lambda-events/LambdaProxyIntegrationEventV2.js index cf7c5ffff..145ae63e3 100644 --- a/src/events/http/lambda-events/LambdaProxyIntegrationEventV2.js +++ b/src/events/http/lambda-events/LambdaProxyIntegrationEventV2.js @@ -39,6 +39,9 @@ export default class LambdaProxyIntegrationEventV2 { this.#request.auth.credentials.context) || {} + // AWS adds the lambda key to the auth context object + const lambdaAuthContext = { lambda: authContext } + let authAuthorizer if (env.AUTHORIZER) { @@ -154,7 +157,7 @@ export default class LambdaProxyIntegrationEventV2 { apiId: 'offlineContext_apiId', authorizer: authAuthorizer || - assign(authContext, { + assign(lambdaAuthContext, { jwt: { claims, scopes, diff --git a/tests/integration/custom-authentication/authenticationCustomVariable.test.js b/tests/integration/custom-authentication/authenticationCustomVariable.test.js index 6a3372030..bb6c9c855 100644 --- a/tests/integration/custom-authentication/authenticationCustomVariable.test.js +++ b/tests/integration/custom-authentication/authenticationCustomVariable.test.js @@ -29,7 +29,7 @@ describe('custom authentication serverless-offline variable tests', function des const json = await response.json() assert.deepEqual( - json.event.requestContext.authorizer.expected, + json.event.requestContext.authorizer.lambda.expected, 'it works', ) })