Previously, the default authority was ROLE_USER when using
oauth2Login() for both OAuth2 and OIDC providers.
* Default authority for OAuth2UserAuthority is now OAUTH2_USER
* Default authority for OidcUserAuthority is now OIDC_USER
Documentation has been updated to include this implementation detail.
Closes gh-7856
@ -302,7 +302,8 @@ The UserInfo Endpoint includes a number of configuration options, as described i
@@ -302,7 +302,8 @@ The UserInfo Endpoint includes a number of configuration options, as described i
[[webflux-oauth2-login-advanced-map-authorities]]
=== Mapping User Authorities
After the user successfully authenticates with the OAuth 2.0 Provider, the `OAuth2User.getAuthorities()` (or `OidcUser.getAuthorities()`) may be mapped to a new set of `GrantedAuthority` instances, which will be supplied to `OAuth2AuthenticationToken` when completing the authentication.
After the user successfully authenticates with the OAuth 2.0 Provider, the `OAuth2User.getAuthorities()` (or `OidcUser.getAuthorities()`) contains a list of granted authorities populated from `OAuth2UserRequest.getAccessToken().getScopes()` and prefixed with `SCOPE_`.
These granted authorities may be mapped to a new set of `GrantedAuthority` instances, which will be supplied to `OAuth2AuthenticationToken` when completing the authentication.
[TIP]
`OAuth2AuthenticationToken.getAuthorities()` is used for authorizing requests, such as in `hasRole('USER')` or `hasRole('ADMIN')`.
@ -316,6 +317,8 @@ There are a couple of options to choose from when mapping user authorities:
@@ -316,6 +317,8 @@ There are a couple of options to choose from when mapping user authorities:
The `GrantedAuthoritiesMapper` is given a list of granted authorities which contains a special authority of type `OAuth2UserAuthority` and the authority string `OAUTH2_USER` (or `OidcUserAuthority` and the authority string `OIDC_USER`).
Register a `GrantedAuthoritiesMapper` `@Bean` to have it automatically applied to the configuration, as shown in the following example:
@ -425,7 +425,8 @@ The UserInfo Endpoint includes a number of configuration options, as described i
@@ -425,7 +425,8 @@ The UserInfo Endpoint includes a number of configuration options, as described i
[[oauth2login-advanced-map-authorities]]
=== Mapping User Authorities
After the user successfully authenticates with the OAuth 2.0 Provider, the `OAuth2User.getAuthorities()` (or `OidcUser.getAuthorities()`) can be mapped to a new set of `GrantedAuthority` instances, which are supplied to `OAuth2AuthenticationToken` when completing the authentication.
After the user successfully authenticates with the OAuth 2.0 Provider, the `OAuth2User.getAuthorities()` (or `OidcUser.getAuthorities()`) contains a list of granted authorities populated from `OAuth2UserRequest.getAccessToken().getScopes()` and prefixed with `SCOPE_`.
These granted authorities can be mapped to a new set of `GrantedAuthority` instances, which are supplied to `OAuth2AuthenticationToken` when completing the authentication.
[TIP]
`OAuth2AuthenticationToken.getAuthorities()` is used for authorizing requests, such as in `hasRole('USER')` or `hasRole('ADMIN')`.
@ -439,6 +440,8 @@ There are a couple of options to choose from when mapping user authorities:
@@ -439,6 +440,8 @@ There are a couple of options to choose from when mapping user authorities:
The `GrantedAuthoritiesMapper` is given a list of granted authorities which contains a special authority of type `OAuth2UserAuthority` and the authority string `OAUTH2_USER` (or `OidcUserAuthority` and the authority string `OIDC_USER`).
Provide an implementation of `GrantedAuthoritiesMapper` and configure it, as follows:
@ -48,13 +48,13 @@ public class OidcUserAuthority extends OAuth2UserAuthority {
@@ -48,13 +48,13 @@ public class OidcUserAuthority extends OAuth2UserAuthority {
@ -43,11 +43,11 @@ public class OAuth2UserAuthority implements GrantedAuthority {
@@ -43,11 +43,11 @@ public class OAuth2UserAuthority implements GrantedAuthority {