Skip to content

Commit fd22f65

Browse files
Add introspection_endpoint to oauth2 schema
1 parent a99722c commit fd22f65

File tree

6 files changed

+65
-11
lines changed

6 files changed

+65
-11
lines changed

deps/oauth2_client/include/oauth2_client.hrl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@
4343
-define(RESPONSE_TOKEN_ENDPOINT, <<"token_endpoint">>).
4444
-define(RESPONSE_AUTHORIZATION_ENDPOINT, <<"authorization_endpoint">>).
4545
-define(RESPONSE_END_SESSION_ENDPOINT, <<"end_session_endpoint">>).
46+
-define(RESPONSE_INTROSPECTION_ENDPOINT, <<"introspection_endpoint">>).
4647
-define(RESPONSE_JWKS_URI, <<"jwks_uri">>).
4748
-define(RESPONSE_TLS_OPTIONS, <<"ssl_options">>).

deps/oauth2_client/include/types.hrl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
token_endpoint :: option(uri_string:uri_string()),
1717
authorization_endpoint :: option(uri_string:uri_string()),
1818
end_session_endpoint :: option(uri_string:uri_string()),
19-
jwks_uri :: option(uri_string:uri_string())
19+
jwks_uri :: option(uri_string:uri_string()),
20+
introspection_endpoint :: option(uri_string:uri_string()),
2021
}).
2122
-type openid_configuration() :: #openid_configuration{}.
2223

@@ -29,6 +30,7 @@
2930
authorization_endpoint :: option(uri_string:uri_string()),
3031
end_session_endpoint :: option(uri_string:uri_string()),
3132
jwks_uri :: option(uri_string:uri_string()),
33+
introspection_endpoint :: option(uri_string:uri_string()),
3234
ssl_options :: option(list())
3335
}).
3436

deps/oauth2_client/src/oauth2_client.erl

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,15 @@ merge_openid_configuration(OpenId, OAuthProvider0) ->
120120
EndSessionEndpoint ->
121121
OAuthProvider2#oauth_provider{end_session_endpoint = EndSessionEndpoint}
122122
end,
123-
case OpenId#openid_configuration.jwks_uri of
123+
OAuthProvider4 = case OpenId#openid_configuration.introspection_endpoint of
124124
undefined -> OAuthProvider3;
125+
IntrospectionEndpoint ->
126+
OAuthProvider3#oauth_provider{introspection_endpoint = IntrospectionEndpoint}
127+
end,
128+
case OpenId#openid_configuration.jwks_uri of
129+
undefined -> OAuthProvider4;
125130
JwksUri ->
126-
OAuthProvider3#oauth_provider{jwks_uri = JwksUri}
131+
OAuthProvider4#oauth_provider{jwks_uri = JwksUri}
127132
end.
128133

129134
-spec merge_oauth_provider(oauth_provider(), proplists:proplist()) ->
@@ -144,10 +149,10 @@ merge_oauth_provider(OAuthProvider, Proplist) ->
144149
EndSessionEndpoint -> [{end_session_endpoint, EndSessionEndpoint} |
145150
proplists:delete(end_session_endpoint, Proplist1)]
146151
end,
147-
Proplist3 = case OAuthProvider#oauth_provider.tokeninfo_endpoint of
152+
Proplist3 = case OAuthProvider#oauth_provider.introspection_endpoint of
148153
undefined -> Proplist2;
149-
TokenInfoEndpoint -> [{tokeninfo_endpoint, TokenInfoEndpoint} |
150-
proplists:delete(tokeninfo_endpoint, Proplist2)]
154+
IntrospectionEndpoint -> [{introspection_endpoint, IntrospectionEndpoint} |
155+
proplists:delete(introspection_endpoint, Proplist2)]
151156
end,
152157
case OAuthProvider#oauth_provider.jwks_uri of
153158
undefined -> Proplist3;
@@ -181,6 +186,8 @@ map_to_openid_configuration(Map) ->
181186
Map, undefined),
182187
end_session_endpoint = maps:get(?RESPONSE_END_SESSION_ENDPOINT,
183188
Map, undefined),
189+
introspection_endpoint = maps:get(?RESPONSE_INTROSPECTION_ENDPOINT,
190+
Map, undefined),
184191
jwks_uri = maps:get(?RESPONSE_JWKS_URI, Map, undefined)
185192
}.
186193

@@ -220,6 +227,10 @@ do_update_oauth_provider_endpoints_configuration(OAuthProvider) when
220227
undefined -> do_nothing;
221228
EndSessionEndpoint -> set_env(end_session_endpoint, EndSessionEndpoint)
222229
end,
230+
case OAuthProvider#oauth_provider.introspection_endpoint of
231+
undefined -> do_nothing;
232+
IntrospectionEndpoint -> set_env(introspection_endpoint, IntrospectionEndpoint)
233+
end,
223234
case OAuthProvider#oauth_provider.jwks_uri of
224235
undefined -> do_nothing;
225236
JwksUri -> set_env(jwks_uri, JwksUri)
@@ -400,6 +411,7 @@ lookup_root_oauth_provider() ->
400411
token_endpoint = get_env(token_endpoint),
401412
authorization_endpoint = get_env(authorization_endpoint),
402413
end_session_endpoint = get_env(end_session_endpoint),
414+
introspection_endpoint = get_env(introspection_endpoint),
403415
ssl_options = extract_ssl_options_as_list(Map)
404416
}.
405417

@@ -589,6 +601,8 @@ map_to_oauth_provider(PropList) when is_list(PropList) ->
589601
proplists:get_value(authorization_endpoint, PropList, undefined),
590602
end_session_endpoint =
591603
proplists:get_value(end_session_endpoint, PropList, undefined),
604+
introspection_endpoint =
605+
proplists:get_value(introspection_endpoint, PropList, undefined),
592606
jwks_uri =
593607
proplists:get_value(jwks_uri, PropList, undefined),
594608
ssl_options =
@@ -639,13 +653,14 @@ format_oauth_provider(OAuthProvider) ->
639653
lists:flatten(io_lib:format("{id: ~p, issuer: ~p, discovery_endpoint: ~p, " ++
640654
" token_endpoint: ~p, " ++
641655
"authorization_endpoint: ~p, end_session_endpoint: ~p, " ++
642-
"jwks_uri: ~p, ssl_options: ~p }", [
656+
"introspection_endpoint: ~p, jwks_uri: ~p, ssl_options: ~p }", [
643657
format_oauth_provider_id(OAuthProvider#oauth_provider.id),
644658
OAuthProvider#oauth_provider.issuer,
645659
OAuthProvider#oauth_provider.discovery_endpoint,
646660
OAuthProvider#oauth_provider.token_endpoint,
647661
OAuthProvider#oauth_provider.authorization_endpoint,
648662
OAuthProvider#oauth_provider.end_session_endpoint,
663+
OAuthProvider#oauth_provider.introspection_endpoint,
649664
OAuthProvider#oauth_provider.jwks_uri,
650665
format_ssl_options(OAuthProvider#oauth_provider.ssl_options)])).
651666

deps/oauth2_client/test/unit_SUITE.erl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ merge_oauth_provider(_) ->
109109
{token_endpoint, OAuthProvider4#oauth_provider.token_endpoint}],
110110
Proplist5),
111111

112+
OAuthProvider5 = OAuthProvider4#oauth_provider{introspection_endpoint = "https://introspection"},
113+
Proplist6 = oauth2_client:merge_oauth_provider(OAuthProvider5, Proplist5),
114+
?assertEqual([{jwks_uri, OAuthProvider5#oauth_provider.jwks_uri},
115+
{end_session_endpoint, OAuthProvider5#oauth_provider.end_session_endpoint},
116+
{authorization_endpoint, OAuthProvider5#oauth_provider.authorization_endpoint},
117+
{token_endpoint, OAuthProvider5#oauth_provider.token_endpoint},
118+
{introspection_endpoint, OAuthProvider5#oauth_provider.introspection_endpoint}],
119+
Proplist6),
120+
112121
% ensure id, issuer, ssl_options and discovery_endpoint are not affected
113122
?assertEqual(OAuthProvider#oauth_provider.id,
114123
OAuthProvider4#oauth_provider.id),

deps/rabbitmq_auth_backend_oauth2/include/oauth2.hrl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
additional_scopes_key :: binary() | undefined,
4949
preferred_username_claims :: list(),
5050
scope_aliases :: map() | undefined,
51-
oauth_provider_id :: oauth_provider_id()
51+
oauth_provider_id :: oauth_provider_id(),
52+
oauth_client_id :: binary() | undefined,
53+
oauth_client_secret :: binary() | undefined
5254
}).
5355

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

deps/rabbitmq_auth_backend_oauth2/priv/schema/rabbitmq_auth_backend_oauth2.schema

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@
153153
rabbit_oauth2_schema:translate_signing_keys(Conf)
154154
end}.
155155

156+
%% When RabbitMQ sends a request to the authorization server, such as to validate a token,
157+
%% it must authenticate with the authorization server
158+
159+
{mapping,
160+
"auth_oauth2.oauth_client_id",
161+
"rabbitmq_auth_backend_oauth2.oauth_client_id",
162+
[{datatype, string}]}.
163+
164+
{mapping,
165+
"auth_oauth2.oauth_client_secret",
166+
"rabbitmq_auth_backend_oauth2.oauth_client_secret",
167+
[{datatype, string}]}.
168+
156169
{mapping,
157170
"auth_oauth2.issuer",
158171
"rabbitmq_auth_backend_oauth2.issuer",
@@ -201,8 +214,8 @@
201214
end}.
202215

203216
{mapping,
204-
"auth_oauth2.tokeninfo_endpoint",
205-
"rabbitmq_auth_backend_oauth2.tokeninfo_endpoint",
217+
"auth_oauth2.introspection_endpoint",
218+
"rabbitmq_auth_backend_oauth2.introspection_endpoint",
206219
[{datatype, string}, {validators, ["uri", "https_uri"]}]}.
207220

208221
{mapping,
@@ -297,7 +310,7 @@
297310
}.
298311

299312
{mapping,
300-
"auth_oauth2.oauth_providers.$name.tokeninfo_endpoint",
313+
"auth_oauth2.oauth_providers.$name.introspection_endpoint",
301314
"rabbitmq_auth_backend_oauth2.oauth_providers",
302315
[{datatype, string}, {validators, ["uri", "https_uri"]}]
303316
}.
@@ -419,6 +432,18 @@
419432
"rabbitmq_auth_backend_oauth2.resource_servers",
420433
[{datatype, string}]}.
421434

435+
%% When RabbitMQ sends a request to the authorization server, such as to validate a token,
436+
%% it must authenticate with the authorization server
437+
{mapping,
438+
"auth_oauth2.resource_servers.$name.oauth_client_id",
439+
"rabbitmq_auth_backend_oauth2.resource_servers",
440+
[{datatype, string}]}.
441+
442+
{mapping,
443+
"auth_oauth2.resource_servers.$name.oauth_client_secret",
444+
"rabbitmq_auth_backend_oauth2.resource_servers",
445+
[{datatype, string}]}.
446+
422447

423448
{translation, "rabbitmq_auth_backend_oauth2.resource_servers",
424449
fun(Conf) ->

0 commit comments

Comments
 (0)