@nrfcloud/api-gateway-authorizer
Advanced tools
Comparing version 1.1.0 to 1.2.0
28
index.js
@@ -48,2 +48,19 @@ 'use strict' | ||
const cognitoIdentities = {} | ||
const getCognitoIdentityForToken = (token, payload) => { | ||
const {iss, sub} = payload | ||
if (!cognitoIdentities[sub]) { | ||
cognitoIdentities[sub] = ci | ||
.getId({ | ||
IdentityPoolId: process.env.identity_pool_id, | ||
Logins: { | ||
[iss.replace(/^https:\/\//, '')]: token | ||
} | ||
}) | ||
.promise() | ||
} | ||
return cognitoIdentities[sub] | ||
} | ||
exports.handler = (event, context, callback) => { | ||
@@ -81,11 +98,4 @@ const bearerToken = event.authorizationToken | ||
}) | ||
.then(payload => ci | ||
.getId({ | ||
IdentityPoolId: process.env.identity_pool_id, | ||
Logins: { | ||
[payload.iss.replace(/^https:\/\//, '')]: token | ||
} | ||
}) | ||
.promise() | ||
.then(({IdentityId}) => callback(null, { | ||
.then(payload => getCognitoIdentityForToken(token, payload) | ||
.then(IdentityId => callback(null, { | ||
principalId: IdentityId, | ||
@@ -92,0 +102,0 @@ policyDocument: { |
{ | ||
"name": "@nrfcloud/api-gateway-authorizer", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Custom authorizer for API Gateway", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7429
115