Skip to content

Commit

Permalink
Merge pull request #654 from BorjaMacedo/master
Browse files Browse the repository at this point in the history
Added claims field to authorizer requestContext for lambda integratio…
  • Loading branch information
dherault committed Jun 2, 2019
2 parents 62486b8 + ec3223a commit ad633d8
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/createVelocityContext.js
@@ -1,4 +1,6 @@
const jsEscapeString = require('js-string-escape');
const jwt = require('jsonwebtoken');

const utils = require('./utils');
const jsonPath = require('./jsonPath');

Expand Down Expand Up @@ -27,11 +29,29 @@ module.exports = function createVelocityContext(request, options, payload) {
const authPrincipalId = request.auth && request.auth.credentials && request.auth.credentials.user;
const headers = request.unprocessedHeaders;

let token = headers && (headers.Authorization || headers.authorization);

if (token && token.split(' ')[0] === 'Bearer') {
token = token.split(' ')[1];
}

let claims;

if (token) {
try {
claims = jwt.decode(token) || undefined;
}
catch (err) {
// Nothing
}
}

return {
context: {
apiId: 'offlineContext_apiId',
authorizer: {
principalId: authPrincipalId || process.env.PRINCIPAL_ID || 'offlineContext_authorizer_principalId', // See #24
claims,
},
httpMethod: request.method.toUpperCase(),
identity: {
Expand Down

0 comments on commit ad633d8

Please sign in to comment.