Skip to content

Commit 4e1ac93

Browse files
committed
Store config expiration value in the json obj
1 parent 89535da commit 4e1ac93

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/lua/api-gateway/validation/oauth2/oauthTokenValidator.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ end
116116

117117
function _M:storeTokenInCache(cacheLookupKey, cachingObj, expire_at_ms_utc)
118118
local expires_in_s = self:getExpiresIn(expire_at_ms_utc)
119-
if ngx.var.max_auth_local_cache_ttl ~= nil and ngx.var.max_auth_local_cache_ttl ~= '' then
120-
expires_in_s = math.min(expires_in_s, ngx.var.max_auth_local_cache_ttl)
121-
end
122119
if (expires_in_s <= 0) then
123120
ngx.log(ngx.DEBUG, "OAuth Token was not persisted in the cache as it has expired at:" .. tostring(expire_at_ms_utc) .. ", while now is:" .. tostring(ngx.time() * 1000) .. " ms.")
124121
return nil
@@ -146,7 +143,11 @@ function _M:extractContextVars(tokenInfo)
146143
cachingObj.oauth_token_scope = tokenInfo.token.scope
147144
cachingObj.oauth_token_client_id = tokenInfo.token.client_id
148145
cachingObj.oauth_token_user_id = tokenInfo.token.user_id
149-
cachingObj.oauth_token_expires_at = tokenInfo.expires_at -- NOTE: Assumption: value in ms
146+
local oauth_token_expires_at = tokenInfo.expires_at
147+
if ngx.var.max_auth_local_cache_ttl ~= nil and ngx.var.max_auth_local_cache_ttl ~= '' then
148+
oauth_token_expires_at = math.min(oauth_token_expires_at, ngx.var.max_auth_local_cache_ttl * 1000)
149+
end
150+
cachingObj.oauth_token_expires_at = oauth_token_expires_at
150151
return cachingObj
151152
end
152153

0 commit comments

Comments
 (0)