Class OAuth2AuthorizationGrantBuilder
java.lang.Object
com.linecorp.armeria.client.auth.oauth2.OAuth2AuthorizationGrantBuilder
A builder for
OAuth2AuthorizationGrant
which represents an OAuth 2.0 Access Token Grant flow.-
Method Summary
Modifier and TypeMethodDescriptionaccessTokenRequest
(AccessTokenRequest accessTokenRequest) Sets theAccessTokenRequest
to be used when requesting an access token.accessTokenRequest
(Supplier<AccessTokenRequest> accessTokenRequestSupplier) Sets theSupplier
ofAccessTokenRequest
to be used when requesting an access token.build()
Returns a newly createdOAuth2AuthorizationGrant
based on the configuration set so far.fallbackTokenProvider
(Supplier<CompletableFuture<? extends GrantedOAuth2AccessToken>> fallbackTokenProvider) Sets an optionalSupplier
to acquire an access token before requesting it to the authorization server.newTokenConsumer
(Consumer<? super GrantedOAuth2AccessToken> newTokenConsumer) Sets an optional hook which gets executed whenever a new token is issued.refreshBefore
(Duration refreshBefore) Sets a period when the token should be refreshed proactively prior to its expiry.responseHandler
(OAuth2ResponseHandler<GrantedOAuth2AccessToken> responseHandler) Sets a customOAuth2ResponseHandler
to handle the response of an access token request.
-
Method Details
-
accessTokenRequest
Sets theAccessTokenRequest
to be used when requesting an access token.Either an
AccessTokenRequest
or theSupplier
of anAccessTokenRequest
must be set before building anOAuth2AuthorizationGrant
. -
accessTokenRequest
public OAuth2AuthorizationGrantBuilder accessTokenRequest(Supplier<AccessTokenRequest> accessTokenRequestSupplier) Sets theSupplier
ofAccessTokenRequest
to be used when requesting an access token. The supplier will be invoked every time when an access token is requested.Either an
AccessTokenRequest
or theSupplier
of anAccessTokenRequest
must be set before building anOAuth2AuthorizationGrant
. -
responseHandler
public OAuth2AuthorizationGrantBuilder responseHandler(OAuth2ResponseHandler<GrantedOAuth2AccessToken> responseHandler) Sets a customOAuth2ResponseHandler
to handle the response of an access token request. If not set, the default response handler will be used. -
refreshBefore
Sets a period when the token should be refreshed proactively prior to its expiry. -
fallbackTokenProvider
public OAuth2AuthorizationGrantBuilder fallbackTokenProvider(Supplier<CompletableFuture<? extends GrantedOAuth2AccessToken>> fallbackTokenProvider) Sets an optionalSupplier
to acquire an access token before requesting it to the authorization server. If the providedGrantedOAuth2AccessToken
is valid, the client doesn't request a new token.This is supposed to be used with
newTokenConsumer(Consumer)
and gets executed in the following cases:- Before the first attempt to acquire an access token.
- Before a subsequent attempt after token issue or refresh failure.
- See Also:
-
newTokenConsumer
public OAuth2AuthorizationGrantBuilder newTokenConsumer(Consumer<? super GrantedOAuth2AccessToken> newTokenConsumer) Sets an optional hook which gets executed whenever a new token is issued.This can be used in combination with
fallbackTokenProvider(Supplier)
to store a newly issued access token which will then be retrieved by invoking the fallback token provider. -
build
Returns a newly createdOAuth2AuthorizationGrant
based on the configuration set so far.
-