Class OAuth2ResourceOwnerPasswordCredentialsGrant

java.lang.Object
com.linecorp.armeria.client.auth.oauth2.OAuth2ResourceOwnerPasswordCredentialsGrant
All Implemented Interfaces:
OAuth2AuthorizationGrant

@UnstableApi public final class OAuth2ResourceOwnerPasswordCredentialsGrant extends Object
An implementation of OAuth 2.0 Resource Owner Password Credentials Grant flow to obtain Access Token, as per [RFC6749], Section 4.3. Implements Access Token loading, storing, obtaining and refreshing.
  • Method Details

    • builder

      public static OAuth2ResourceOwnerPasswordCredentialsGrantBuilder builder(WebClient accessTokenEndpoint, String accessTokenEndpointPath)
      Parameters:
      accessTokenEndpoint - A WebClient to facilitate an Access Token request. Must correspond to the Access Token endpoint of the OAuth 2 system.
      accessTokenEndpointPath - A URI path that corresponds to the Access Token endpoint of the
    • getAccessToken

      public CompletionStage<GrantedOAuth2AccessToken> getAccessToken()
      Issues an OAuth 2.0 Access Token and cache it in memory and returns the cached one until the token is considered valid. It automatically refreshes the cached token once it's considered expired and returns the refreshed one.

      Renewing a token is guaranteed to be atomic even though the method is invoked by multiple threads.

      It optionally tries to load an access token from AbstractOAuth2AuthorizationGrantBuilder.fallbackTokenProvider(Supplier) or AbstractOAuth2AuthorizationGrantBuilder.fallbackTokenProvider(Supplier) which supposedly gets one by querying to a longer term storage, before it makes a request to the authorization server.

      One may choose to provide a hook which gets executed every time a token is issued or refreshed from the authorization server to store the renewed token to a longer term storage via AbstractOAuth2AuthorizationGrantBuilder.newTokenConsumer(Consumer) or AbstractOAuth2AuthorizationGrantBuilder.newTokenConsumer(Consumer).

      Specified by:
      getAccessToken in interface OAuth2AuthorizationGrant