Skip to content

Commit

Permalink
Added support for AUTHORIZER env var in lambda integration
Browse files Browse the repository at this point in the history
Fixes dherault#816 for v6
  • Loading branch information
jormaechea committed Sep 24, 2019
1 parent 578fe63 commit 35d4512
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/events/http/lambda-events/VelocityContext.js
Expand Up @@ -50,10 +50,22 @@ export default class VelocityContext {
this._request.auth.credentials &&
this._request.auth.credentials.principalId

let authorizer =
this._request.auth &&
this._request.auth.credentials &&
this._request.auth.credentials.authorizer
let authorizer

if (process.env.AUTHORIZER) {
try {
authorizer = JSON.parse(process.env.AUTHORIZER)
} catch (error) {
console.error(
'Serverless-offline: Could not parse process.env.AUTHORIZER, make sure it is correct JSON.',
)
}
} else {
authorizer =
this._request.auth &&
this._request.auth.credentials &&
this._request.auth.credentials.authorizer
}

// NOTE FIXME request.raw.req.rawHeaders can only be null for testing (hapi shot inject())
const headers = parseHeaders(this._request.raw.req.rawHeaders || [])
Expand All @@ -67,6 +79,7 @@ export default class VelocityContext {
if (!authorizer) authorizer = {}

authorizer.principalId =
authorizer.principalId ||
authPrincipalId ||
process.env.PRINCIPAL_ID ||
'offlineContext_authorizer_principalId' // See #24
Expand Down

0 comments on commit 35d4512

Please sign in to comment.