rabbitmq-auth-backend-oauth2: correctly map additional_scopes_key

This commit is contained in:
Hathoute 2024-11-18 17:42:59 +01:00
parent 047cc5a084
commit 0d799a50eb
2 changed files with 12 additions and 3 deletions

View File

@ -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.
@ -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).

View File

@ -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.">>}
@ -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.">>}