Skip to content

Commit 42b982c

Browse files
Add auth and token endpoint params to authSettings
1 parent 07f8ca1 commit 42b982c

File tree

3 files changed

+69
-14
lines changed

3 files changed

+69
-14
lines changed

deps/rabbitmq_management/priv/schema/rabbitmq_management.schema

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,11 +568,11 @@ end}.
568568
"rabbitmq_management.oauth_resource_servers",
569569
[{datatype, {enum, [sp_initiated, idp_initiated]}}]}.
570570

571-
{mapping, "management.oauth_resource_servers.$name.authorization_endpoint_params.$name",
571+
{mapping, "management.oauth_resource_servers.$name.oauth_authorization_endpoint_params.$name",
572572
""rabbitmq_management.oauth_resource_servers",
573573
[{datatype, string}]}.
574574

575-
{mapping, "management.oauth_resource_servers.$name.token_endpoint_params.$name",
575+
{mapping, "management.oauth_resource_servers.$name.oauth_token_endpoint_params.$name",
576576
""rabbitmq_management.oauth_resource_servers",
577577
[{datatype, string}]}.
578578

deps/rabbitmq_management/src/rabbit_mgmt_wm_auth.erl

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ variances(Req, Context) ->
2525
content_types_provided(ReqData, Context) ->
2626
{rabbit_mgmt_util:responder_map(to_json), ReqData, Context}.
2727

28+
merge_property(Key, List, MapIn) ->
29+
case proplists:get_value(Key, List) of
30+
undefined -> MapIn;
31+
V0 -> MapIn#{Key => V0}
32+
end.
33+
34+
extract_oauth_provider_info_props_as_map(ManagementProps) ->
35+
lists:foldl(fun(K, Acc) ->
36+
merge_property(K, ManagementProps, Acc) end, #{}, [oauth_provider_url,
37+
oauth_metadata_url, oauth_authorization_endpoint_params,
38+
oauth_token_endpoint_params]).
39+
2840
merge_oauth_provider_info(OAuthResourceServer, MgtResourceServer, ManagementProps) ->
2941
OAuthProviderResult = case proplists:get_value(oauth_provider_id, OAuthResourceServer) of
3042
undefined -> oauth2_client:get_oauth_provider([issuer]);
@@ -35,15 +47,17 @@ merge_oauth_provider_info(OAuthResourceServer, MgtResourceServer, ManagementProp
3547
{error, _} -> #{}
3648
end,
3749
OAuthProviderInfo1 = maps:merge(OAuthProviderInfo0,
38-
case proplists:get_value(oauth_provider_url, ManagementProps) of
39-
undefined -> #{};
40-
V1 -> #{oauth_provider_url => V1}
41-
end),
50+
extract_oauth_provider_info_props_as_map(ManagementProps)),
4251
maps:merge(OAuthProviderInfo1, proplists:to_map(MgtResourceServer)).
4352

4453
oauth_provider_to_map(OAuthProvider) ->
4554
% only include issuer and end_session_endpoint for now. The other endpoints are resolved by oidc-client library
46-
Map0 = #{ oauth_provider_url => OAuthProvider#oauth_provider.issuer },
55+
Map0 = case OAuthProvider#oauth_provider.issuer of
56+
undefined -> #{};
57+
Issuer -> #{ oauth_provider_url => Issuer,
58+
oauth_metadata_url => OAuthProvider#oauth_provider.discovery_endpoint
59+
}
60+
end,
4761
case OAuthProvider#oauth_provider.end_session_endpoint of
4862
undefined -> Map0;
4963
V -> maps:put(end_session_endpoint, V, Map0)
@@ -75,12 +89,22 @@ getAllDeclaredOauth2Resources(OAuth2BackendProps) ->
7589
OAuth2Resources = proplists:get_value(resource_servers, OAuth2BackendProps, #{}),
7690
case proplists:get_value(resource_server_id, OAuth2BackendProps) of
7791
undefined -> OAuth2Resources;
78-
Id -> maps:put(Id, [{id, Id}], OAuth2Resources)
92+
Id -> maps:put(Id, buildRootResourceServerIfAny(Id, OAuth2BackendProps),
93+
OAuth2Resources)
7994
end.
80-
buildRootResourceServerIfAny(Props) ->
81-
[ {id, proplists:get_value(resource_server_id, Props) },
82-
{oauth_client_id, proplists:get_value(oauth_client_id, Props)},
83-
{oauth_client_id, proplists:get_value(oauth_client_id, Props)} ].
95+
buildRootResourceServerIfAny(Id, Props) ->
96+
[ {id, Id},
97+
{oauth_client_id,
98+
proplists:get_value(oauth_client_id, Props)},
99+
{oauth_client_secret,
100+
proplists:get_value(oauth_client_secret, Props)},
101+
{oauth_response_type,
102+
proplists:get_value(oauth_response_type, Props)},
103+
{authorization_endpoint_params,
104+
proplists:get_value(authorization_endpoint_params, Props)},
105+
{token_endpoint_params,
106+
proplists:get_value(token_endpoint_params, Props)}
107+
].
84108

85109
authSettings() ->
86110
ManagementProps = application:get_all_env(rabbitmq_management),

deps/rabbitmq_management/test/rabbit_mgmt_wm_auth_SUITE.erl

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,13 @@ groups() ->
7474
should_return_disabled_auth_settings,
7575
{with_mgt_oauth_client_id_z, [], [
7676
should_return_mgt_oauth_provider_url_url1,
77+
should_return_mgt_oauth_metadata_url_url1,
7778
{with_mgt_oauth_provider_url_url0, [], [
78-
should_return_mgt_oauth_provider_url_url0
79+
should_return_mgt_oauth_provider_url_url0,
80+
should_return_mgt_oauth_metadata_url_url1,
81+
{with_mgt_oauth_metadata_url_url0, [], [
82+
should_return_mgt_oauth_metadata_url_url0
83+
]}
7984
]}
8085
]}
8186
]}
@@ -299,10 +304,15 @@ init_per_suite(Config) ->
299304
{idp2, <<"idp2">>},
300305
{idp3, <<"idp3">>},
301306
{idp1_url, <<"https://idp1">>},
307+
{idp1_meta_url, <<"https://idp1/.well-known/openid-configuration">>},
302308
{idp2_url, <<"https://idp2">>},
309+
{idp2_meta_url, <<"https://idp2/.well-known/openid-configuration">>},
303310
{idp3_url, <<"https://idp3">>},
311+
{idp3_meta_url, <<"https://idp3/.well-known/openid-configuration">>},
304312
{url0, <<"https://url0">>},
313+
{meta_url0, <<"https://url0/.well-known/openid-configuration">>},
305314
{url1, <<"https://url1">>},
315+
{meta_url1, <<"https://url1/.well-known/openid-configuration">>},
306316
{logout_url_0, <<"https://logout_0">>},
307317
{logout_url_1, <<"https://logout_1">>},
308318
{logout_url_2, <<"https://logout_2">>},
@@ -340,6 +350,9 @@ init_per_group(with_mgt_oauth_client_secret_q, Config) ->
340350
init_per_group(with_mgt_oauth_provider_url_url0, Config) ->
341351
application:set_env(rabbitmq_management, oauth_provider_url, ?config(url0, Config)),
342352
Config;
353+
init_per_group(with_mgt_oauth_metadata_url_url0, Config) ->
354+
application:set_env(rabbitmq_management, oauth_metadata_url, ?config(meta_url0, Config)),
355+
Config;
343356
init_per_group(with_root_issuer_url1, Config) ->
344357
application:set_env(rabbitmq_auth_backend_oauth2, issuer, ?config(url1, Config)),
345358
Config;
@@ -542,6 +555,14 @@ should_return_mgt_oauth_provider_url_url1(Config) ->
542555
assertEqual_on_attribute_for_oauth_resource_server(rabbit_mgmt_wm_auth:authSettings(),
543556
Config, rabbit, oauth_provider_url, url1).
544557

558+
should_return_mgt_oauth_metadata_url_url1(Config) ->
559+
assertEqual_on_attribute_for_oauth_resource_server(rabbit_mgmt_wm_auth:authSettings(),
560+
Config, rabbit, oauth_metadata_url, meta_url1).
561+
562+
should_return_mgt_oauth_metadata_url_url0(Config) ->
563+
assertEqual_on_attribute_for_oauth_resource_server(rabbit_mgmt_wm_auth:authSettings(),
564+
Config, rabbit, oauth_metadata_url, meta_url0).
565+
545566
should_return_mgt_oauth_provider_url_url0(Config) ->
546567
assertEqual_on_attribute_for_oauth_resource_server(rabbit_mgmt_wm_auth:authSettings(),
547568
Config, rabbit, oauth_provider_url, url0).
@@ -585,6 +606,10 @@ should_return_oauth_resource_server_rabbit_with_oauth_provider_url_url1(Config)
585606
assertEqual_on_attribute_for_oauth_resource_server(rabbit_mgmt_wm_auth:authSettings(),
586607
Config, rabbit, oauth_provider_url, url1).
587608

609+
should_return_oauth_resource_server_rabbit_with_oauth_metadata_url_url1(Config) ->
610+
assertEqual_on_attribute_for_oauth_resource_server(rabbit_mgmt_wm_auth:authSettings(),
611+
Config, rabbit, oauth_provider_url, url1 ).
612+
588613
should_return_oauth_resource_server_rabbit_with_oauth_provider_url_url0(Config) ->
589614
assertEqual_on_attribute_for_oauth_resource_server(rabbit_mgmt_wm_auth:authSettings(),
590615
Config, rabbit, oauth_provider_url, url0).
@@ -617,9 +642,9 @@ should_not_return_oauth_scopes(_Config) ->
617642

618643
should_return_oauth_enabled(_Config) ->
619644
Actual = rabbit_mgmt_wm_auth:authSettings(),
620-
log(Actual),
621645
?assertEqual(true, proplists:get_value(oauth_enabled, Actual)).
622646

647+
623648
should_return_oauth_idp_initiated_logon(_Config) ->
624649
Actual = rabbit_mgmt_wm_auth:authSettings(),
625650
?assertEqual(<<"idp_initiated">>, proplists:get_value(oauth_initiated_logon_type, Actual)).
@@ -699,6 +724,12 @@ assertEqual_on_attribute_for_oauth_resource_server(Actual, Config, ConfigKey, At
699724
end,
700725
?assertEqual(Value, proplists:get_value(Attribute, OauthResource)).
701726

727+
assert_attribute_is_defined_for_oauth_resource_server(Actual, Config, ConfigKey, Attribute) ->
728+
log(Actual),
729+
OAuthResourceServers = proplists:get_value(oauth_resource_servers, Actual),
730+
OauthResource = maps:get(?config(ConfigKey, Config), OAuthResourceServers),
731+
?assertEqual(true, proplists:is_defined(Attribute, OauthResource)).
732+
702733
assert_attribute_not_defined_for_oauth_resource_server(Actual, Config, ConfigKey, Attribute) ->
703734
log(Actual),
704735
OAuthResourceServers = proplists:get_value(oauth_resource_servers, Actual),

0 commit comments

Comments
 (0)