Skip to content

Commit

Permalink
rabbitmq-auth-backend-oauth2: correctly map additional_scopes_key
Browse files Browse the repository at this point in the history
  • Loading branch information
Hathoute committed Nov 18, 2024
1 parent 047cc5a commit 0d799a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion deps/rabbitmq_auth_backend_oauth2/src/rabbit_oauth2_schema.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
translate_scope_aliases/1
]).

-define(RESOURCE_SERVERS_SYNONYMS, #{
"additional_scopes_key" => "extra_scopes_source"
}).

resource_servers_key_synonym(Name) ->
case maps:find(Name, ?RESOURCE_SERVERS_SYNONYMS) of {ok, Synonym} -> Synonym;
error -> Name
end.

extract_key_as_binary({Name,_}) -> list_to_binary(Name).
extract_value({_Name,V}) -> V.

Expand Down Expand Up @@ -240,7 +249,7 @@ extract_resource_server_properties(Settings) ->
KeyFun = fun extract_key_as_binary/1,
ValueFun = fun extract_value/1,

OAuthProviders = [{Name, {list_to_atom(Key), list_to_binary(V)}}
OAuthProviders = [{Name, {list_to_atom(resource_servers_key_synonym(Key)), list_to_binary(V)}}
|| {[?AUTH_OAUTH2, ?RESOURCE_SERVERS, Name, Key], V} <- Settings ],
maps:groups_from_list(KeyFun, ValueFun, OAuthProviders).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ test_resource_servers_attributes(_) ->
{["auth_oauth2","resource_servers","rabbitmq1","preferred_username_claims","2"],
"groupid"}
],
#{<<"rabbitmq1xxx">> := [{additional_scopes_key, <<"roles">>},
#{<<"rabbitmq1xxx">> := [{extra_scopes_source, <<"roles">>},
{id, <<"rabbitmq1xxx">>},
{preferred_username_claims, [<<"userid">>, <<"groupid">>]},
{scope_prefix, <<"somescope.">>}
Expand All @@ -186,7 +186,7 @@ test_resource_servers_attributes(_) ->
{["auth_oauth2","resource_servers","rabbitmq1","preferred_username_claims","2"],
"groupid"}
],
#{<<"rabbitmq1">> := [{additional_scopes_key, <<"roles">>},
#{<<"rabbitmq1">> := [{extra_scopes_source, <<"roles">>},
{id, <<"rabbitmq1">>},
{preferred_username_claims, [<<"userid">>, <<"groupid">>]},
{scope_prefix, <<"somescope.">>}
Expand Down

0 comments on commit 0d799a5

Please sign in to comment.