Skip to content

Commit d33ec80

Browse files
authored
Always refresh keys on empty JWK (#339)
1 parent 366f725 commit d33ec80

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

src/oidcc_provider_configuration_worker.erl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ handle_cast(refresh_configuration, State) ->
148148
{noreply, State, {continue, load_configuration}};
149149
handle_cast(refresh_jwks, State) ->
150150
{noreply, State, {continue, load_jwks}};
151+
handle_cast(
152+
{refresh_jwks_for_unknown_kid, _Kid},
153+
#state{jwks = #jose_jwk{keys = {jose_jwk_set, []}}} = State
154+
) ->
155+
{noreply, State, {continue, load_jwks}};
151156
handle_cast({refresh_jwks_for_unknown_kid, Kid}, #state{jwks = Jwks} = State) ->
152157
case has_kid(Jwks, Kid) of
153158
false ->

test/oidcc_provider_configuration_worker_test.erl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,60 @@ retries_with_backoff_with_invalid_issuer_test() ->
6262
meck:unload(httpc),
6363

6464
ok.
65+
66+
refreshes_with_empty_key_set_test() ->
67+
ok = meck:new(httpc, [no_link]),
68+
HttpFun =
69+
fun
70+
(
71+
get,
72+
{"https://example.com/.well-known/openid-configuration", []},
73+
_HttpOpts,
74+
_Opts,
75+
_Profile
76+
) ->
77+
{ok, {
78+
{"HTTP/1.1", 200, "OK"},
79+
[{"content-type", "application/json"}],
80+
jsx:encode(#{
81+
issuer => <<"https://example.com">>,
82+
jwks_uri => <<"https://example.com/keys">>,
83+
authorization_endpoint => <<"https://example.com/authorize">>,
84+
scopes_supported => [<<"openid">>],
85+
response_types_supported => [<<"code">>],
86+
subject_types_supported => [<<"public">>],
87+
id_token_signing_alg_values_supported => [<<"RS256">>]
88+
})
89+
}};
90+
(
91+
get,
92+
{<<"https://example.com/keys">>, []},
93+
_HttpOpts,
94+
_Opts,
95+
_Profile
96+
) ->
97+
{ok, {
98+
{"HTTP/1.1", 200, "OK"},
99+
[{"content-type", "application/json"}],
100+
jsx:encode(#{keys => []})
101+
}}
102+
end,
103+
ok = meck:expect(httpc, request, HttpFun),
104+
105+
process_flag(trap_exit, true),
106+
107+
{ok, Pid} = oidcc_provider_configuration_worker:start_link(#{
108+
issuer => <<"https://example.com">>,
109+
backoff_type => random,
110+
backoff_min => 500,
111+
backoff_max => 500
112+
}),
113+
114+
ok = oidcc_provider_configuration_worker:refresh_jwks_for_unknown_kid(Pid, <<"kid">>),
115+
116+
% Once for Metadata, once for JWKs, and once for JWK refresh
117+
?assert(meck:num_calls(httpc, request, '_') >= 3),
118+
119+
meck:unload(httpc),
120+
121+
ok.

0 commit comments

Comments
 (0)