Reputation: 4029
I have an ResourceServer app (@EnableResourceServer
) connected to an AuthorizationServer (@EnableAuthorizationServer
).
I want to support two grant types:
Both are working correctly, but how can I differentiate if Principal
is basic user (using authorization code flow) or client (using client credentials)?
If is not directly possible do you think I should create a specific role/authority or scope (which is better?) to determine when Principal
is a client?
Upvotes: 2
Views: 805
Reputation: 743
Once you've authenticated, you should have an instance of org.springframework.security.oauth2.provider.OAuth2Authentication set in the SecurityContext which contains details of both the authenticated user and the client they are using.
This has an isClientOnly() method which will return true if the client credentials grant is used. You can also check this in the @PreAuthorize tags if you've enables the OAuth2 expressions:
@PreAuthorize("#oauth2.isClient")
Upvotes: 1