Skip to content

Commit

Permalink
Added support for the AUTHORIZER env variable for LambdaIntegration (…
Browse files Browse the repository at this point in the history
…non-proxy) http requests

This resolves dherault#816
This replaces dherault#818
  • Loading branch information
jormaechea committed Nov 28, 2021
1 parent 7092f3f commit a46b3f5
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 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
Expand All @@ -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,
Expand Down

0 comments on commit a46b3f5

Please sign in to comment.