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 Aug 21, 2024
1 parent 9f3a4fc commit 773f763
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 @@ -1720,6 +1720,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 @@ -1750,20 +1755,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 @@ -1779,6 +1779,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 773f763

Please sign in to comment.