Skip to content

Commit 9f1c626

Browse files
Update settings in schema
1 parent 81f6d6a commit 9f1c626

File tree

5 files changed

+81
-13
lines changed

5 files changed

+81
-13
lines changed

deps/rabbitmq_auth_backend_oauth2/include/oauth2.hrl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
scope_aliases :: map() | undefined,
5151
oauth_provider_id :: oauth_provider_id(),
5252
oauth_client_id :: binary() | undefined,
53-
oauth_client_secret :: binary() | undefined
53+
oauth_client_secret :: binary() | undefined,
54+
access_token_format :: jwt | opaque | undefined
5455
}).
5556

5657
-type resource_server() :: #resource_server{}.

deps/rabbitmq_auth_backend_oauth2/priv/schema/rabbitmq_auth_backend_oauth2.schema

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,31 @@
156156
%% When RabbitMQ sends a request to the authorization server, such as to validate a token,
157157
%% it must authenticate with the authorization server
158158

159+
{mapping,
160+
"auth_oauth2.access_token_format",
161+
"rabbitmq_auth_backend_oauth2.access_token_format",
162+
[{datatype, {enum, [jwt, opaque]}}]}.
163+
159164
{mapping,
160165
"auth_oauth2.oauth_client_id",
161166
"rabbitmq_auth_backend_oauth2.oauth_client_id",
162167
[{datatype, string}]}.
163168

169+
{translation,
170+
"rabbitmq_auth_backend_oauth2.oauth_client_id",
171+
fun(Conf) -> list_to_binary(cuttlefish:conf_get("auth_oauth2.oauth_client_id", Conf))
172+
end}.
173+
164174
{mapping,
165175
"auth_oauth2.oauth_client_secret",
166176
"rabbitmq_auth_backend_oauth2.oauth_client_secret",
167177
[{datatype, string}]}.
168178

179+
{translation,
180+
"rabbitmq_auth_backend_oauth2.oauth_client_secret",
181+
fun(Conf) -> list_to_binary(cuttlefish:conf_get("auth_oauth2.oauth_client_secret", Conf))
182+
end}.
183+
169184
{mapping,
170185
"auth_oauth2.issuer",
171186
"rabbitmq_auth_backend_oauth2.issuer",
@@ -444,6 +459,10 @@
444459
"rabbitmq_auth_backend_oauth2.resource_servers",
445460
[{datatype, string}]}.
446461

462+
{mapping,
463+
"auth_oauth2.resource_servers.$name.access_token_format",
464+
"rabbitmq_auth_backend_oauth2.resource_servers",
465+
[{datatype, {enum, [jwt, opaque]}}]}.
447466

448467
{translation, "rabbitmq_auth_backend_oauth2.resource_servers",
449468
fun(Conf) ->

deps/rabbitmq_auth_backend_oauth2/src/rabbit_oauth2_resource_server.erl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ new_resource_server(ResourceServerId) ->
2424
additional_scopes_key = undefined,
2525
preferred_username_claims = ?DEFAULT_PREFERRED_USERNAME_CLAIMS,
2626
scope_aliases = undefined,
27-
oauth_provider_id = root
27+
oauth_provider_id = root,
28+
access_token_format = jwt
2829
}.
2930

3031
-spec resolve_resource_server_from_audience(binary() | list() | none) ->
@@ -85,6 +86,8 @@ get_root_resource_server() ->
8586
end,
8687
ScopePrefix =
8788
get_env(scope_prefix, DefaultScopePrefix),
89+
AccessTokenFormat =
90+
get_env(access_token_format, jwt),
8891
OAuthProviderId =
8992
case get_env(default_oauth_provider) of
9093
undefined -> root;
@@ -99,6 +102,7 @@ get_root_resource_server() ->
99102
additional_scopes_key = AdditionalScopesKey,
100103
preferred_username_claims = PreferredUsernameClaims,
101104
scope_aliases = ScopeAliases,
105+
access_token_format = AccessTokenFormat,
102106
oauth_provider_id = OAuthProviderId
103107
}.
104108

@@ -143,6 +147,9 @@ get_resource_server(ResourceServerId, RootResourseServer) when
143147
undefined -> erlang:iolist_to_binary([ResourceServerId, <<".">>]);
144148
Prefix -> Prefix
145149
end),
150+
AccessTokenFormat =
151+
proplists:get_value(access_token_format, ResourceServerProps,
152+
RootResourseServer#resource_server.access_token_format),
146153
OAuthProviderId =
147154
proplists:get_value(oauth_provider_id, ResourceServerProps,
148155
RootResourseServer#resource_server.oauth_provider_id),
@@ -155,7 +162,8 @@ get_resource_server(ResourceServerId, RootResourseServer) when
155162
additional_scopes_key = AdditionalScopesKey,
156163
preferred_username_claims = PreferredUsernameClaims,
157164
scope_aliases = ScopeAliases,
158-
oauth_provider_id = OAuthProviderId
165+
oauth_provider_id = OAuthProviderId,
166+
access_token_format = AccessTokenFormat
159167
}.
160168

161169
-spec find_audience(binary() | list(), list()) ->

deps/rabbitmq_auth_backend_oauth2/src/rabbit_oauth2_schema.erl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,22 @@ extract_oauth_providers_properties(Settings) ->
244244
extract_resource_server_properties(Settings) ->
245245
KeyFun = fun extract_key_as_binary/1,
246246
ValueFun = fun extract_value/1,
247-
248-
OAuthProviders = [{Name, {list_to_atom(resource_servers_key_synonym(Key)), list_to_binary(V)}}
247+
MapValueFun = fun(V) ->
248+
case V of
249+
jwt -> V;
250+
opaque -> V;
251+
_ -> list_to_binary(V)
252+
end end,
253+
254+
ResourceServers = [{Name, {list_to_atom(resource_servers_key_synonym(Key)), MapValueFun(V)}}
249255
|| {[?AUTH_OAUTH2, ?RESOURCE_SERVERS, Name, Key], V} <- Settings ],
250-
maps:groups_from_list(KeyFun, ValueFun, OAuthProviders).
256+
maps:groups_from_list(KeyFun, ValueFun, ResourceServers).
251257

252258
mapOauthProviderProperty({Key, Value}) ->
253259
{Key, case Key of
254260
issuer -> validator_https_uri(Key, Value);
255261
token_endpoint -> validator_https_uri(Key, Value);
256-
tokeninfo_endpoint -> validator_https_uri(Key, Value);
262+
introspection_endpoint -> validator_https_uri(Key, Value);
257263
jwks_uri -> validator_https_uri(Key, Value);
258264
end_session_endpoint -> validator_https_uri(Key, Value);
259265
authorization_endpoint -> validator_https_uri(Key, Value);

deps/rabbitmq_auth_backend_oauth2/test/config_schema_SUITE_data/rabbitmq_auth_backend_oauth2.snippets

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
{resource_server_type,<<"new_resource_server_type">>},
3232
{extra_scopes_source, <<"my_custom_scope_key">>},
3333
{preferred_username_claims, [<<"user_name">>, <<"username">>, <<"email">>]},
34-
{verify_aud, true},
34+
{verify_aud, true},
3535
{issuer, "https://my-jwt-issuer"},
3636
{discovery_endpoint_path, "/.well-known/openid-configuration"},
3737
{discovery_endpoint_params, [
@@ -96,14 +96,14 @@
9696
{jwks_uri, "https://my-jwt-issuer/jwks.json"},
9797
{resource_servers,
9898
#{
99+
<<"rabbitmq-customers">> => [
100+
{extra_scopes_source, <<"roles">>},
101+
{id, <<"rabbitmq-customers">>}
102+
],
99103
<<"rabbitmq-operations">> => [
100104
{scope_prefix, <<"api://">>},
101105
{id, <<"rabbitmq-operations">>}
102-
],
103-
<<"rabbitmq-customers">> => [
104-
{extra_scopes_source, <<"roles">>},
105-
{id, <<"rabbitmq-customers">>}
106-
]
106+
]
107107
}
108108
},
109109
{key_config, [
@@ -326,5 +326,39 @@
326326
{extra_scopes_source, <<"roles realm.roles">> }
327327
]}
328328
], []
329+
},
330+
{token_introspection,
331+
"auth_oauth2.resource_server_id = new_resource_server_id
332+
auth_oauth2.introspection_endpoint = https://introspect
333+
auth_oauth2.access_token_format = jwt
334+
auth_oauth2.oauth_client_id = rabbit
335+
auth_oauth2.oauth_client_secret = rabbit_secret
336+
auth_oauth2.oauth_providers.p.introspection_endpoint = https://introspect_p
337+
auth_oauth2.resource_servers.b.access_token_format = opaque
338+
auth_oauth2.resource_servers.b.oauth_client_id = rabbit_b
339+
auth_oauth2.resource_servers.b.oauth_client_secret = rabbit_secret_b",
340+
[
341+
{rabbitmq_auth_backend_oauth2, [
342+
{introspection_endpoint, "https://introspect"},
343+
{oauth_client_secret, <<"rabbit_secret">> },
344+
{oauth_client_id, <<"rabbit">> },
345+
{access_token_format, jwt},
346+
{resource_server_id,<<"new_resource_server_id">>},
347+
{oauth_providers, #{
348+
<<"p">> => [
349+
{introspection_endpoint, "https://introspect_p"}
350+
]
351+
}},
352+
{resource_servers, #{
353+
<<"b">> => [
354+
{oauth_client_secret, <<"rabbit_secret_b">>},
355+
{oauth_client_id, <<"rabbit_b">>},
356+
{access_token_format, opaque},
357+
{id, <<"b">>}
358+
]
359+
}}
360+
361+
]}
362+
], []
329363
}
330364
].

0 commit comments

Comments
 (0)