I have a claim named user_name
within my JWT and also corresponding user-name-attribute
set as user_name
in spring security oauth2 client provider proper property:
spring.security.oauth2.client.provider.my-oauth-provider.user-name-attribute=user_name
I can also see this property is properly being read by ReactiveClientRegistrationRepository
class (ClientRegistration.ProviderDetails.UserInfoEndpoint
). But when I read SecurityContextHolder.getContext().getAuthentication().getName()
on Resource Server I can see the value taken from (default) sub
- IdTokenClaimNames.SUB
claim.
Why is that? Do I still miss some additional configuration also on resource server side to have specified user-name-attribute
taken and returned by SecurityContextHolder.getContext().getAuthentication().getName()
on Resource Server? I understand that only Bearer token (and maybe some cookies) is being sent from client to resource server so maybe also some other filter is needed on Gateway/client side - just guessing?