@@ -124,7 +124,7 @@ expiry_timestamp(#auth_user{impl = DecodedTokenFun}) ->
124124authenticate (_ , AuthProps0 ) ->
125125 AuthProps = to_map (AuthProps0 ),
126126 Token = token_from_context (AuthProps ),
127-
127+
128128 case check_token (Token ) of
129129 % % avoid logging the token
130130 {error , _ } = E -> E ;
@@ -247,10 +247,10 @@ post_process_payload_with_scope_alias_in_extra_scopes_source(ResourceServerId, P
247247 ExtraScopesField = rabbit_oauth2_config :get_additional_scopes_key (ResourceServerId ),
248248 case ExtraScopesField of
249249 % % nothing to inject
250- undefined -> Payload ;
251- _ ->
250+ { error , not_found } -> Payload ;
251+ { ok , ExtraScopes } ->
252252 ScopeMappings = rabbit_oauth2_config :get_scope_aliases (ResourceServerId ),
253- post_process_payload_with_scope_alias_field_named (Payload , ExtraScopesField , ScopeMappings )
253+ post_process_payload_with_scope_alias_field_named (Payload , ExtraScopes , ScopeMappings )
254254 end .
255255
256256
@@ -281,38 +281,42 @@ post_process_payload_with_scope_alias_field_named(Payload, FieldName, ScopeAlias
281281
282282-spec does_include_complex_claim_field (ResourceServerId :: binary (), Payload :: map ()) -> boolean ().
283283does_include_complex_claim_field (ResourceServerId , Payload ) when is_map (Payload ) ->
284- case rabbit_oauth2_config :has_additional_scopes_key (ResourceServerId ) of
285- true -> maps :is_key (rabbit_oauth2_config : get_additional_scopes_key ( ResourceServerId ) , Payload );
286- false -> false
284+ case rabbit_oauth2_config :get_additional_scopes_key (ResourceServerId ) of
285+ { ok , ScopeKey } -> maps :is_key (ScopeKey , Payload );
286+ { error , not_found } -> false
287287 end .
288288
289289-spec post_process_payload_with_complex_claim (ResourceServerId :: binary (), Payload :: map ()) -> map ().
290290post_process_payload_with_complex_claim (ResourceServerId , Payload ) ->
291- ComplexClaim = maps :get (rabbit_oauth2_config :get_additional_scopes_key (ResourceServerId ), Payload ),
292- AdditionalScopes =
293- case ComplexClaim of
294- L when is_list (L ) -> L ;
295- M when is_map (M ) ->
296- case maps :get (ResourceServerId , M , undefined ) of
297- undefined -> [];
298- Ks when is_list (Ks ) ->
299- [erlang :iolist_to_binary ([ResourceServerId , <<" ." >>, K ]) || K <- Ks ];
300- ClaimBin when is_binary (ClaimBin ) ->
301- UnprefixedClaims = binary :split (ClaimBin , <<" " >>, [global , trim_all ]),
302- [erlang :iolist_to_binary ([ResourceServerId , <<" ." >>, K ]) || K <- UnprefixedClaims ];
303- _ -> []
304- end ;
305- Bin when is_binary (Bin ) ->
306- binary :split (Bin , <<" " >>, [global , trim_all ]);
307- _ -> []
308- end ,
309-
310- case AdditionalScopes of
311- [] -> Payload ;
312- _ ->
313- ExistingScopes = maps :get (? SCOPE_JWT_FIELD , Payload , []),
314- maps :put (? SCOPE_JWT_FIELD , AdditionalScopes ++ ExistingScopes , Payload )
315- end .
291+ case rabbit_oauth2_config :get_additional_scopes_key (ResourceServerId ) of
292+ {ok , ScopesKey } ->
293+ ComplexClaim = maps :get (ScopesKey , Payload ),
294+ AdditionalScopes =
295+ case ComplexClaim of
296+ L when is_list (L ) -> L ;
297+ M when is_map (M ) ->
298+ case maps :get (ResourceServerId , M , undefined ) of
299+ undefined -> [];
300+ Ks when is_list (Ks ) ->
301+ [erlang :iolist_to_binary ([ResourceServerId , <<" ." >>, K ]) || K <- Ks ];
302+ ClaimBin when is_binary (ClaimBin ) ->
303+ UnprefixedClaims = binary :split (ClaimBin , <<" " >>, [global , trim_all ]),
304+ [erlang :iolist_to_binary ([ResourceServerId , <<" ." >>, K ]) || K <- UnprefixedClaims ];
305+ _ -> []
306+ end ;
307+ Bin when is_binary (Bin ) ->
308+ binary :split (Bin , <<" " >>, [global , trim_all ]);
309+ _ -> []
310+ end ,
311+
312+ case AdditionalScopes of
313+ [] -> Payload ;
314+ _ ->
315+ ExistingScopes = maps :get (? SCOPE_JWT_FIELD , Payload , []),
316+ maps :put (? SCOPE_JWT_FIELD , AdditionalScopes ++ ExistingScopes , Payload )
317+ end ;
318+ {error , not_found } -> Payload
319+ end .
316320
317321-spec post_process_payload_in_keycloak_format (Payload :: map ()) -> map ().
318322% % keycloak token format: https://github.com/rabbitmq/rabbitmq-auth-backend-oauth2/issues/36
0 commit comments