Class DefaultOAuth2AuthorizedClientManager
- All Implemented Interfaces:
OAuth2AuthorizedClientManager
OAuth2AuthorizedClientManager for use within
the context of a HttpServletRequest.
(When operating outside of the context of a HttpServletRequest, use
AuthorizedClientServiceOAuth2AuthorizedClientManager instead.)
Authorized Client Persistence
This manager utilizes an OAuth2AuthorizedClientRepository to persist
OAuth2AuthorizedClients.
By default, when an authorization attempt succeeds, the OAuth2AuthorizedClient
will be saved in the OAuth2AuthorizedClientRepository. This functionality can
be changed by configuring a custom OAuth2AuthorizationSuccessHandler via
setAuthorizationSuccessHandler(OAuth2AuthorizationSuccessHandler).
By default, when an authorization attempt fails due to an
"invalid_grant" error, the previously saved
OAuth2AuthorizedClient will be removed from the
OAuth2AuthorizedClientRepository. (The "invalid_grant"
error can occur when a refresh token that is no longer valid is used to retrieve a new
access token.) This functionality can be changed by configuring a custom
OAuth2AuthorizationFailureHandler via
setAuthorizationFailureHandler(OAuth2AuthorizationFailureHandler).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe default implementation of thecontextAttributesMapper. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultOAuth2AuthorizedClientManager(ClientRegistrationRepository clientRegistrationRepository, OAuth2AuthorizedClientRepository authorizedClientRepository) Constructs aDefaultOAuth2AuthorizedClientManagerusing the provided parameters. -
Method Summary
Modifier and TypeMethodDescriptionauthorize(OAuth2AuthorizeRequest authorizeRequest) Attempt to authorize or re-authorize (if required) theclientidentified by the providedclientRegistrationId.voidsetAuthorizationFailureHandler(OAuth2AuthorizationFailureHandler authorizationFailureHandler) Sets theOAuth2AuthorizationFailureHandlerthat handles authorization failures.voidsetAuthorizationSuccessHandler(OAuth2AuthorizationSuccessHandler authorizationSuccessHandler) Sets theOAuth2AuthorizationSuccessHandlerthat handles successful authorizations.voidsetAuthorizedClientProvider(OAuth2AuthorizedClientProvider authorizedClientProvider) Sets theOAuth2AuthorizedClientProviderused for authorizing (or re-authorizing) an OAuth 2.0 Client.voidsetContextAttributesMapper(Function<OAuth2AuthorizeRequest, Map<String, Object>> contextAttributesMapper) Sets theFunctionused for mapping attribute(s) from theOAuth2AuthorizeRequestto aMapof attributes to be associated to theauthorization context.
-
Constructor Details
-
DefaultOAuth2AuthorizedClientManager
public DefaultOAuth2AuthorizedClientManager(ClientRegistrationRepository clientRegistrationRepository, OAuth2AuthorizedClientRepository authorizedClientRepository) Constructs aDefaultOAuth2AuthorizedClientManagerusing the provided parameters.- Parameters:
clientRegistrationRepository- the repository of client registrationsauthorizedClientRepository- the repository of authorized clients
-
-
Method Details
-
authorize
Description copied from interface:OAuth2AuthorizedClientManagerAttempt to authorize or re-authorize (if required) theclientidentified by the providedclientRegistrationId. Implementations must returnnullif authorization is not supported for the specified client, e.g. the associatedOAuth2AuthorizedClientProvider(s) does not support theauthorization granttype configured for the client.In the case of re-authorization, implementations must return the provided
authorized clientif re-authorization is not supported for the client OR is not required, e.g. arefresh tokenis not available OR theaccess tokenis not expired.- Specified by:
authorizein interfaceOAuth2AuthorizedClientManager- Parameters:
authorizeRequest- the authorize request- Returns:
- the
OAuth2AuthorizedClientornullif authorization is not supported for the specified client
-
setAuthorizedClientProvider
Sets theOAuth2AuthorizedClientProviderused for authorizing (or re-authorizing) an OAuth 2.0 Client.- Parameters:
authorizedClientProvider- theOAuth2AuthorizedClientProviderused for authorizing (or re-authorizing) an OAuth 2.0 Client
-
setContextAttributesMapper
public void setContextAttributesMapper(Function<OAuth2AuthorizeRequest, Map<String, Object>> contextAttributesMapper) Sets theFunctionused for mapping attribute(s) from theOAuth2AuthorizeRequestto aMapof attributes to be associated to theauthorization context.- Parameters:
contextAttributesMapper- theFunctionused for supplying theMapof attributes to theauthorization context
-
setAuthorizationSuccessHandler
public void setAuthorizationSuccessHandler(OAuth2AuthorizationSuccessHandler authorizationSuccessHandler) Sets theOAuth2AuthorizationSuccessHandlerthat handles successful authorizations.The default saves
OAuth2AuthorizedClients in theOAuth2AuthorizedClientRepository.- Parameters:
authorizationSuccessHandler- theOAuth2AuthorizationSuccessHandlerthat handles successful authorizations- Since:
- 5.3
-
setAuthorizationFailureHandler
public void setAuthorizationFailureHandler(OAuth2AuthorizationFailureHandler authorizationFailureHandler) Sets theOAuth2AuthorizationFailureHandlerthat handles authorization failures.A
RemoveAuthorizedClientOAuth2AuthorizationFailureHandleris used by default.- Parameters:
authorizationFailureHandler- theOAuth2AuthorizationFailureHandlerthat handles authorization failures- Since:
- 5.3
- See Also:
-