Skip to content

Commit

Permalink
feat: add lambda proxy authorizer enhancedAuthContext
Browse files Browse the repository at this point in the history
  • Loading branch information
frsechet committed Aug 11, 2019
1 parent c6e3e1b commit abcc0fd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/config/offline-default.req.vm
Expand Up @@ -17,6 +17,8 @@
"query": $loop,
#set( $map = $input.params().path )
"path": $loop,
#set( $map = $context.enhancedAuthContext )
"enhancedAuthContext": $loop,
#set( $map = $context.identity )
"identity": $loop,
#set( $map = $stageVariables )
Expand Down
9 changes: 9 additions & 0 deletions src/createAuthScheme.js
Expand Up @@ -132,6 +132,8 @@ module.exports = function createAuthScheme(

event.methodArn = `arn:aws:execute-api:${options.region}:${accountId}:${apiId}/${options.stage}/${httpMethod}${resourcePath}`

event.enhancedAuthContext = {}

event.requestContext = {
accountId,
apiId,
Expand Down Expand Up @@ -204,13 +206,20 @@ module.exports = function createAuthScheme(
`Authorization function returned a successful response: (λ: ${authFunName})`,
)

const enhancedAuthContext = {
principalId: policy.principalId,
integrationLatency: '42',
...policy.context,
}

// Set the credentials for the rest of the pipeline
return resolve(
h.authenticated({
credentials: {
context: policy.context,
usageIdentifierKey: policy.usageIdentifierKey,
user: policy.principalId,
enhancedAuthContext,
},
}),
)
Expand Down
5 changes: 5 additions & 0 deletions src/createVelocityContext.js
Expand Up @@ -39,6 +39,10 @@ module.exports = function createVelocityContext(request, options, payload) {
const path = (x) => jsonPath(payload || {}, x)
const authPrincipalId =
request.auth && request.auth.credentials && request.auth.credentials.user
const enhancedAuthContext =
request.auth &&
request.auth.credentials &&
request.auth.credentials.enhancedAuthContext
const headers = request.unprocessedHeaders

let token = headers && (headers.Authorization || headers.authorization)
Expand Down Expand Up @@ -67,6 +71,7 @@ module.exports = function createVelocityContext(request, options, payload) {
process.env.PRINCIPAL_ID ||
'offlineContext_authorizer_principalId', // See #24
},
enhancedAuthContext: enhancedAuthContext || {},
httpMethod: request.method.toUpperCase(),
identity: {
accountId: 'offlineContext_accountId',
Expand Down

0 comments on commit abcc0fd

Please sign in to comment.