Skip to content

Commit 986311a

Browse files
Opaque token working on management ui
Refactoring needed so that the resolved jwt token is kept in the management ui so that the backend does not need to reoolve it permanentely
1 parent b5f233f commit 986311a

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

deps/rabbitmq_auth_backend_oauth2/include/oauth2.hrl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
%% Key JWT fields
1717
%%
1818

19+
-define(ACTIVE_FIELD, <<"active">>). %% FOR INTROSPECTED TOKENS
1920
-define(AUD_JWT_FIELD, <<"aud">>).
2021
-define(SCOPE_JWT_FIELD, <<"scope">>).
2122
-define(TAG_SCOPE_PREFIX, <<"tag:">>).

deps/rabbitmq_auth_backend_oauth2/src/rabbit_auth_backend_oauth2.erl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ authenticate(_, AuthProps0) ->
188188
{error, Error} -> {refused, "Unable to introspect token: ~p", [Error]}
189189
end.
190190

191-
192191
-spec with_decoded_token(Token, Fun) -> Result
193192
when Token :: decoded_jwt_token(),
194193
Fun :: auth_user_extraction_fun(),
@@ -236,8 +235,11 @@ validate_token_expiry(#{}) -> ok.
236235
{'error', term() } |
237236
{'refused', 'signature_invalid' | {'error', term()} | {'invalid_aud', term()}}.
238237

239-
check_token(DecodedToken, _) when is_map(DecodedToken) ->
240-
{ok, DecodedToken};
238+
check_token(DecodedToken, {ResourceServer, _}) when is_map(DecodedToken) ->
239+
case maps:is_key(?ACTIVE_FIELD, DecodedToken) of
240+
false -> {ok, DecodedToken};
241+
true -> {ok, normalize_token_scope(ResourceServer, DecodedToken)}
242+
end;
241243

242244
check_token(Token, {ResourceServer, InternalOAuthProvider}) ->
243245
case decode_and_verify(Token, ResourceServer, InternalOAuthProvider) of
@@ -258,15 +260,14 @@ extract_scopes_from_scope_claim(Payload) ->
258260
-spec normalize_token_scope(
259261
ResourceServer :: resource_server(), DecodedToken :: decoded_jwt_token()) -> map().
260262
normalize_token_scope(ResourceServer, Payload) ->
261-
262263
filter_duplicates(
263264
filter_matching_scope_prefix(ResourceServer,
264265
extract_scopes_from_rich_auth_request(ResourceServer,
265266
extract_scopes_using_scope_aliases(ResourceServer,
266267
extract_scopes_from_additional_scopes_key(ResourceServer,
267268
extract_scopes_from_requesting_party_token(ResourceServer,
268269
extract_scopes_from_scope_claim(Payload))))))).
269-
270+
270271
filter_duplicates(#{?SCOPE_JWT_FIELD := Scopes} = Payload) ->
271272
set_scope(lists:usort(Scopes), Payload);
272273
filter_duplicates(Payload) -> Payload.
@@ -493,5 +494,6 @@ resolve_scope_var(Elem, Token, Vhost) ->
493494
-spec tags_from(decoded_jwt_token()) -> list(atom()).
494495
tags_from(DecodedToken) ->
495496
Scopes = maps:get(?SCOPE_JWT_FIELD, DecodedToken, []),
497+
rabbit_log:debug("tags_from Scopes : ~p", [Scopes]),
496498
TagScopes = filter_matching_scope_prefix_and_drop_it(Scopes, ?TAG_SCOPE_PREFIX),
497499
lists:usort(lists:map(fun rabbit_data_coercion:to_atom/1, TagScopes)).

selenium/test/oauth/env.spring

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export OAUTH_SERVER_CONFIG_DIR=${OAUTH_SERVER_CONFIG_BASEDIR}/oauth/spring
2-
export OAUTH_SCOPES="openid profile rabbitmq.tag:management"
2+
export OAUTH_SCOPES="openid profile rabbitmq.tag:management rabbitmq.tag:administrator"
33
export OAUTH_CLIENT_ID=rabbitmq_client_code

selenium/test/oauth/rabbitmq.opaque-token.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ auth_oauth2.access_token_format = opaque
22
auth_oauth2.introspection_client_auth_method = basic
33
auth_oauth2.introspection_client_id = introspection_client
44
auth_oauth2.introspection_client_secret = introspection_client
5+
auth_oauth2.verify_aud = false

selenium/test/oauth/spring/application.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ spring:
7474
provider: spring
7575
client-id: rabbitmq_client_code_opaque
7676
client-secret: "{noop}rabbitmq_client_code_opaque"
77-
require-proof-key: true
78-
token-settings:
79-
access-token-format: reference
77+
require-proof-key: true
8078
authorization-grant-types:
8179
- authorization_code
8280
client-authentication-methods:
@@ -91,6 +89,8 @@ spring:
9189
- rabbitmq.tag:administrator
9290
- rabbitmq.tag:management
9391
client-name: rabbitmq_client_code_opaque
92+
token:
93+
access-token-format: reference
9494
rabbitmq_client_code:
9595
registration:
9696
provider: spring

0 commit comments

Comments
 (0)