Skip to content

Commit 03ec1d3

Browse files
committed
Enable caching of negative introspection responses
1 parent 4702769 commit 03ec1d3

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/resty/openidc.lua

+10-6
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,11 @@ function openidc.introspect(opts)
17801780

17811781
if v then
17821782
json = cjson.decode(v)
1783+
1784+
if not json or not json.active then
1785+
err = "invalid cached token"
1786+
end
1787+
17831788
return json, err
17841789
end
17851790

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

1813-
18141818
if not json then
18151819
return json, err
18161820
end
18171821

1818-
if not json.active then
1819-
err = "invalid token"
1820-
return json, err
1821-
end
1822-
18231822
-- cache the results
18241823
local introspection_cache_ignore = opts.introspection_cache_ignore or false
18251824
local expiry_claim = opts.introspection_expiry_claim or "exp"
18261825

1826+
18271827
if not introspection_cache_ignore and json[expiry_claim] then
18281828
local introspection_interval = opts.introspection_interval or 0
18291829
local ttl = json[expiry_claim]
@@ -1839,6 +1839,10 @@ function openidc.introspect(opts)
18391839
set_cached_introspection(opts, access_token, cjson.encode(json), ttl)
18401840
end
18411841

1842+
if not json.active then
1843+
err = "invalid token"
1844+
end
1845+
18421846
return json, err
18431847

18441848
end

0 commit comments

Comments
 (0)