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

Added claims field to authorizer requestContext for lambda integratio… #654

Merged
merged 1 commit into from Jun 2, 2019
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
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