Skip to content

Commit

Permalink
feat: document_overrides quirk to patch invalid OIDD files
Browse files Browse the repository at this point in the history
  • Loading branch information
paulswartz committed Dec 14, 2023
1 parent d7f80c3 commit 68101dd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/oidcc_provider_configuration.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@

-type quirks() :: #{
allow_issuer_mismatch => boolean(),
allow_unsafe_http => boolean()
allow_unsafe_http => boolean(),
document_overrides => map()
}.
%% Allow Specification Non-compliance
%%
Expand All @@ -45,6 +46,8 @@
%% and function parameter</li>
%% <li>`allow_unsafe_http' - Allow unsafe HTTP. Use this for development
%% providers and <strong>never in production</strong>.</li>
%% <li>`document_overrides' - a map to merge with the real OIDD document,
%% in case the OP left out some values.</li>
%% </ul>

-type opts() :: #{
Expand Down Expand Up @@ -277,10 +280,13 @@ load_jwks(JwksUri, Opts) ->
%% @since 3.1.0
-spec decode_configuration(Configuration, Opts) -> {ok, t()} | {error, error()} when
Configuration :: map(), Opts :: opts().
decode_configuration(Configuration, Opts) ->
decode_configuration(Configuration0, Opts) ->
Quirks = maps:get(quirks, Opts, #{}),
AllowUnsafeHttp = maps:get(allow_unsafe_http, Quirks, false),

DocumentOverrides = maps:get(document_overrides, Quirks, #{}),
Configuration = maps:merge(Configuration0, DocumentOverrides),

maybe
{ok, {
#{
Expand Down
14 changes: 14 additions & 0 deletions test/oidcc_provider_configuration_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,20 @@ allow_unsafe_http_quirk_test() ->

ok.

document_overrides_quirk_test() ->
PrivDir = code:priv_dir(oidcc),
{ok, Configuration} = file:read_file(PrivDir ++ "/test/fixtures/google-metadata.json"),

?assertMatch(
{ok, #oidcc_provider_configuration{
issuer = <<"https://example.com">>
}},
oidcc_provider_configuration:decode_configuration(jose:decode(Configuration), #{
quirks => #{document_overrides => #{<<"issuer">> => <<"https://example.com">>}}
})
),
ok.

uri_concatenation_test() ->
ok = meck:new(httpc, [no_link]),
HttpFun =
Expand Down

0 comments on commit 68101dd

Please sign in to comment.