From a46b3f561f4ab107db27213e348e584e95b10883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Ormaechea?= Date: Sat, 27 Nov 2021 23:57:02 -0300 Subject: [PATCH] Added support for the AUTHORIZER env variable for LambdaIntegration (non-proxy) http requests This resolves #816 This replaces #818 --- .../lambda-events/LambdaIntegrationEvent.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) 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,