Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the AUTHORIZER env variable for LambdaIntegration #1308

Merged
merged 2 commits into from Apr 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 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,30 @@ export default class LambdaIntegrationEvent {
}

create() {
if (process.env.AUTHORIZER) {
try {
const authorizerContext = parse(process.env.AUTHORIZER)
if (authorizerContext) {
this.#request.auth = {
...this.#request.auth,
credentials: {
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