Skip to content

Commit 432ce40

Browse files
committed
Send auth cache desired ttl to cache function
1 parent c231e39 commit 432ce40

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = function(options) {
2121
for (let e of events) {
2222
const authSource = getObjectPath(['authorizer', 'identitySource'], e);
2323
const authValidatorExp = getObjectPath(['authorizer', 'identityValidationExpression'], e);
24+
const authCacheTtl = getObjectPath(['authorizer', 'resultTtlInSeconds'], e);
2425
const authorizerFunction = (
2526
getObjectPath(getObjectPath(['authorizer', 'arn'], e) || '', options.authorizers) ||
2627
getObjectPath(getObjectPath(['authorizer', 'name'], e) || '', slsHandlers)
@@ -43,7 +44,8 @@ module.exports = function(options) {
4344
authorizerCheckCallback(
4445
authorizerFunction,
4546
options.setCacheEntry,
46-
options.getCacheEntry
47+
options.getCacheEntry,
48+
authCacheTtl
4749
)
4850
] : []),
4951
...(e.cors ? [decorateAddCORSCallback()] : []),

lib/authorizer-callbacks.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ module.exports.authorizerValidationCallback = function(
6565
module.exports.authorizerCheckCallback = function(
6666
authorizer,
6767
setCacheEntry,
68-
getCacheEntry
68+
getCacheEntry,
69+
cacheEntryTtl
6970
) {
7071
return function(req, res, next) {
7172
if (!authorizer) {
7273
return next();
7374
}
7475

7576
function authorizerCallback(err, awsAuthDocument) {
76-
// TODO addCacheEntry(req.lambda.authorizer.event.authorizationToken, awsAuthDocument).then
7777
if (err) {
7878
res.status(500).send(err);
7979
} else {
@@ -104,6 +104,7 @@ module.exports.authorizerCheckCallback = function(
104104
(setCacheEntry || function(i, cb) { cb() })({
105105
key: cacheKey,
106106
value: awsAuthDocument,
107+
ttl: cacheEntryTtl || 300,
107108
}, function() {
108109
authorizerCallback(innerErr, awsAuthDocument);
109110
});

0 commit comments

Comments
 (0)