Class PasswordOAuth2AuthorizedClientProvider
- java.lang.Object
-
- org.springframework.security.oauth2.client.PasswordOAuth2AuthorizedClientProvider
-
- All Implemented Interfaces:
OAuth2AuthorizedClientProvider
public final class PasswordOAuth2AuthorizedClientProvider extends java.lang.Object implements OAuth2AuthorizedClientProvider
An implementation of anOAuth2AuthorizedClientProviderfor thepasswordgrant.- Since:
- 5.2
- See Also:
OAuth2AuthorizedClientProvider,DefaultPasswordTokenResponseClient
-
-
Constructor Summary
Constructors Constructor Description PasswordOAuth2AuthorizedClientProvider()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description OAuth2AuthorizedClientauthorize(OAuth2AuthorizationContext context)Attempt to authorize (or re-authorize) theclientin the providedcontext.voidsetAccessTokenResponseClient(OAuth2AccessTokenResponseClient<OAuth2PasswordGrantRequest> accessTokenResponseClient)Sets the client used when requesting an access token credential at the Token Endpoint for thepasswordgrant.voidsetClock(java.time.Clock clock)Sets theClockused inInstant.now(Clock)when checking the access token expiry.voidsetClockSkew(java.time.Duration clockSkew)Sets the maximum acceptable clock skew, which is used when checking theaccess tokenexpiry.
-
-
-
Method Detail
-
authorize
@Nullable public OAuth2AuthorizedClient authorize(OAuth2AuthorizationContext context)
Attempt to authorize (or re-authorize) theclientin the providedcontext. Returnsnullif authorization (or re-authorization) is not supported, e.g. the client'sauthorization grant typeis notpasswordOR theusernameand/orpasswordattributes are not available in the providedcontextOR theaccess tokenis not expired.The following
context attributesare supported:OAuth2AuthorizationContext.USERNAME_ATTRIBUTE_NAME(required) - aStringvalue for the resource owner's usernameOAuth2AuthorizationContext.PASSWORD_ATTRIBUTE_NAME(required) - aStringvalue for the resource owner's password
- Specified by:
authorizein interfaceOAuth2AuthorizedClientProvider- Parameters:
context- the context that holds authorization-specific state for the client- Returns:
- the
OAuth2AuthorizedClientornullif authorization (or re-authorization) is not supported
-
setAccessTokenResponseClient
public void setAccessTokenResponseClient(OAuth2AccessTokenResponseClient<OAuth2PasswordGrantRequest> accessTokenResponseClient)
Sets the client used when requesting an access token credential at the Token Endpoint for thepasswordgrant.- Parameters:
accessTokenResponseClient- the client used when requesting an access token credential at the Token Endpoint for thepasswordgrant
-
setClockSkew
public void setClockSkew(java.time.Duration clockSkew)
Sets the maximum acceptable clock skew, which is used when checking theaccess tokenexpiry. The default is 60 seconds.An access token is considered expired if
OAuth2AccessToken#getExpiresAt() - clockSkewis before the current timeclock#instant().- Parameters:
clockSkew- the maximum acceptable clock skew
-
setClock
public void setClock(java.time.Clock clock)
Sets theClockused inInstant.now(Clock)when checking the access token expiry.- Parameters:
clock- the clock
-
-