Skip to content

Commit

Permalink
Enable caching of negative introspection responses
Browse files Browse the repository at this point in the history
  • Loading branch information
boscard committed Sep 16, 2024
1 parent 4702769 commit 03ec1d3
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/resty/openidc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,11 @@ function openidc.introspect(opts)

if v then
json = cjson.decode(v)

if not json or not json.active then
err = "invalid cached token"
end

return json, err
end

Expand Down Expand Up @@ -1810,20 +1815,15 @@ function openidc.introspect(opts)
end
json, err = openidc.call_token_endpoint(opts, introspection_endpoint, body, opts.introspection_endpoint_auth_method, "introspection")


if not json then
return json, err
end

if not json.active then
err = "invalid token"
return json, err
end

-- cache the results
local introspection_cache_ignore = opts.introspection_cache_ignore or false
local expiry_claim = opts.introspection_expiry_claim or "exp"


if not introspection_cache_ignore and json[expiry_claim] then
local introspection_interval = opts.introspection_interval or 0
local ttl = json[expiry_claim]
Expand All @@ -1839,6 +1839,10 @@ function openidc.introspect(opts)
set_cached_introspection(opts, access_token, cjson.encode(json), ttl)
end

if not json.active then
err = "invalid token"
end

return json, err

end
Expand Down

0 comments on commit 03ec1d3

Please sign in to comment.