diff --git a/src/events/http/lambda-events/LambdaIntegrationEvent.js b/src/events/http/lambda-events/LambdaIntegrationEvent.js index 5a6ffc6e5..4ded00747 100644 --- a/src/events/http/lambda-events/LambdaIntegrationEvent.js +++ b/src/events/http/lambda-events/LambdaIntegrationEvent.js @@ -1,6 +1,8 @@ import renderVelocityTemplateObject from './renderVelocityTemplateObject.js' import VelocityContext from './VelocityContext.js' +const { parse } = JSON + export default class LambdaIntegrationEvent { #path = null #request = null @@ -16,6 +18,28 @@ export default class LambdaIntegrationEvent { } create() { + if (process.env.AUTHORIZER) { + try { + const authorizerContext = parse(process.env.AUTHORIZER) + if (authorizerContext) { + this.#request.auth = { + ...this.#request.auth, + authorizer: authorizerContext, + } + } + } catch (error) { + if (this.log) { + this.log.error( + 'Could not parse process.env.AUTHORIZER, make sure it is correct JSON', + ) + } else { + console.error( + 'Serverless-offline: Could not parse process.env.AUTHORIZER, make sure it is correct JSON.', + ) + } + } + } + const velocityContext = new VelocityContext( this.#request, this.#stage,