Class DefaultReactiveOAuth2UserService

java.lang.Object
org.springframework.security.oauth2.client.userinfo.DefaultReactiveOAuth2UserService
All Implemented Interfaces:
ReactiveOAuth2UserService<OAuth2UserRequest,OAuth2User>

public class DefaultReactiveOAuth2UserService extends Object implements ReactiveOAuth2UserService<OAuth2UserRequest,OAuth2User>
An implementation of an ReactiveOAuth2UserService that supports standard OAuth 2.0 Provider's.

For standard OAuth 2.0 Provider's, the attribute name used to access the user's name from the UserInfo response is required and therefore must be available via UserInfoEndpoint.getUserNameAttributeName().

NOTE: Attribute names are not standardized between providers and therefore will vary. Please consult the provider's API documentation for the set of supported user attribute names.

Since:
5.1
See Also:
  • Constructor Details

    • DefaultReactiveOAuth2UserService

      public DefaultReactiveOAuth2UserService()
  • Method Details

    • loadUser

      public reactor.core.publisher.Mono<OAuth2User> loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException
      Description copied from interface: ReactiveOAuth2UserService
      Returns an OAuth2User after obtaining the user attributes of the End-User from the UserInfo Endpoint.
      Specified by:
      loadUser in interface ReactiveOAuth2UserService<OAuth2UserRequest,OAuth2User>
      Parameters:
      userRequest - the user request
      Returns:
      an OAuth2User
      Throws:
      OAuth2AuthenticationException - if an error occurs while attempting to obtain the user attributes from the UserInfo Endpoint
    • setAttributesConverter

      public void setAttributesConverter(org.springframework.core.convert.converter.Converter<OAuth2UserRequest,org.springframework.core.convert.converter.Converter<Map<String,Object>,Map<String,Object>>> attributesConverter)
      Use this strategy to adapt user attributes into a format understood by Spring Security; by default, the original attributes are preserved.

      This can be helpful, for example, if the user attribute is nested. Since Spring Security needs the username attribute to be at the top level, you can use this method to do:

           DefaultReactiveOAuth2UserService userService = new DefaultReactiveOAuth2UserService();
           userService.setAttributesConverter((userRequest) -> (attributes) ->
               Map<String, Object> userObject = (Map<String, Object>) attributes.get("user");
               attributes.put("user-name", userObject.get("user-name"));
               return attributes;
           });
       
      Parameters:
      attributesConverter - the attribute adaptation strategy to use
      Since:
      6.3
    • setWebClient

      public void setWebClient(org.springframework.web.reactive.function.client.WebClient webClient)
      Sets the WebClient used for retrieving the user endpoint
      Parameters:
      webClient - the client to use