Class OAuth20Service

java.lang.Object
com.github.scribejava.core.oauth.OAuthService
com.github.scribejava.core.oauth.OAuth20Service
All Implemented Interfaces:
java.io.Closeable, java.lang.AutoCloseable

public class OAuth20Service
extends OAuthService
  • Constructor Details

    • OAuth20Service

      public OAuth20Service​(DefaultApi20 api, java.lang.String apiKey, java.lang.String apiSecret, java.lang.String callback, java.lang.String defaultScope, java.lang.String responseType, java.io.OutputStream debugStream, java.lang.String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient)
  • Method Details

    • getVersion

      public java.lang.String getVersion()
      Returns the OAuth version of the service.
      Specified by:
      getVersion in class OAuthService
      Returns:
      OAuth version as string
    • signRequest

      public void signRequest​(java.lang.String accessToken, OAuthRequest request)
    • signRequest

      public void signRequest​(OAuth2AccessToken accessToken, OAuthRequest request)
    • getAuthorizationUrl

      public java.lang.String getAuthorizationUrl()
      Returns the URL where you should redirect your users to authenticate your application.
      Returns:
      the URL where you should redirect your users
    • getAuthorizationUrl

      public java.lang.String getAuthorizationUrl​(java.lang.String state)
    • getAuthorizationUrl

      public java.lang.String getAuthorizationUrl​(java.util.Map<java.lang.String,​java.lang.String> additionalParams)
      Returns the URL where you should redirect your users to authenticate your application.
      Parameters:
      additionalParams - any additional GET params to add to the URL
      Returns:
      the URL where you should redirect your users
    • getAuthorizationUrl

      public java.lang.String getAuthorizationUrl​(PKCE pkce)
    • createAuthorizationUrlBuilder

      public AuthorizationUrlBuilder createAuthorizationUrlBuilder()
    • getApi

      public DefaultApi20 getApi()
    • extractAuthorization

      public OAuth2Authorization extractAuthorization​(java.lang.String redirectLocation)
    • getResponseType

      public java.lang.String getResponseType()
    • getDefaultScope

      public java.lang.String getDefaultScope()
    • logRequestWithParams

      protected void logRequestWithParams​(java.lang.String requestDescription, OAuthRequest request)
    • sendAccessTokenRequestSync

      protected OAuth2AccessToken sendAccessTokenRequestSync​(OAuthRequest request) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Throws:
      java.io.IOException
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
    • sendAccessTokenRequestAsync

      protected java.util.concurrent.Future<OAuth2AccessToken> sendAccessTokenRequestAsync​(OAuthRequest request)
    • sendAccessTokenRequestAsync

      protected java.util.concurrent.Future<OAuth2AccessToken> sendAccessTokenRequestAsync​(OAuthRequest request, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
    • createAccessTokenRequest

      protected OAuthRequest createAccessTokenRequest​(AccessTokenRequestParams params)
    • getAccessTokenAsync

      public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenAsync​(java.lang.String code)
    • getAccessTokenAsync

      public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenAsync​(AccessTokenRequestParams params)
    • getAccessToken

      public OAuth2AccessToken getAccessToken​(java.lang.String code) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Throws:
      java.io.IOException
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
    • getAccessToken

      public OAuth2AccessToken getAccessToken​(AccessTokenRequestParams params) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Throws:
      java.io.IOException
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
    • getAccessToken

      public java.util.concurrent.Future<OAuth2AccessToken> getAccessToken​(AccessTokenRequestParams params, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
      Start the request to retrieve the access token. The optionally provided callback will be called with the Token when it is available.
      Parameters:
      params - params
      callback - optional callback
      Returns:
      Future
    • getAccessToken

      public java.util.concurrent.Future<OAuth2AccessToken> getAccessToken​(java.lang.String code, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
    • createRefreshTokenRequest

      protected OAuthRequest createRefreshTokenRequest​(java.lang.String refreshToken, java.lang.String scope)
    • refreshAccessTokenAsync

      public java.util.concurrent.Future<OAuth2AccessToken> refreshAccessTokenAsync​(java.lang.String refreshToken)
    • refreshAccessTokenAsync

      public java.util.concurrent.Future<OAuth2AccessToken> refreshAccessTokenAsync​(java.lang.String refreshToken, java.lang.String scope)
    • refreshAccessToken

      public OAuth2AccessToken refreshAccessToken​(java.lang.String refreshToken) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Throws:
      java.io.IOException
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
    • refreshAccessToken

      public OAuth2AccessToken refreshAccessToken​(java.lang.String refreshToken, java.lang.String scope) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Throws:
      java.io.IOException
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
    • refreshAccessToken

      public java.util.concurrent.Future<OAuth2AccessToken> refreshAccessToken​(java.lang.String refreshToken, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
    • refreshAccessToken

      public java.util.concurrent.Future<OAuth2AccessToken> refreshAccessToken​(java.lang.String refreshToken, java.lang.String scope, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
    • createAccessTokenPasswordGrantRequest

      protected OAuthRequest createAccessTokenPasswordGrantRequest​(java.lang.String username, java.lang.String password, java.lang.String scope)
    • getAccessTokenPasswordGrant

      public OAuth2AccessToken getAccessTokenPasswordGrant​(java.lang.String username, java.lang.String password) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Throws:
      java.io.IOException
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
    • getAccessTokenPasswordGrant

      public OAuth2AccessToken getAccessTokenPasswordGrant​(java.lang.String username, java.lang.String password, java.lang.String scope) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Throws:
      java.io.IOException
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
    • getAccessTokenPasswordGrantAsync

      public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenPasswordGrantAsync​(java.lang.String username, java.lang.String password)
    • getAccessTokenPasswordGrantAsync

      public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenPasswordGrantAsync​(java.lang.String username, java.lang.String password, java.lang.String scope)
    • getAccessTokenPasswordGrantAsync

      public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenPasswordGrantAsync​(java.lang.String username, java.lang.String password, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
      Request Access Token Password Grant async version
      Parameters:
      username - User name
      password - User password
      callback - Optional callback
      Returns:
      Future
    • getAccessTokenPasswordGrantAsync

      public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenPasswordGrantAsync​(java.lang.String username, java.lang.String password, java.lang.String scope, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
    • createAccessTokenClientCredentialsGrantRequest

      protected OAuthRequest createAccessTokenClientCredentialsGrantRequest​(java.lang.String scope)
    • getAccessTokenClientCredentialsGrantAsync

      public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenClientCredentialsGrantAsync()
    • getAccessTokenClientCredentialsGrantAsync

      public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenClientCredentialsGrantAsync​(java.lang.String scope)
    • getAccessTokenClientCredentialsGrant

      public OAuth2AccessToken getAccessTokenClientCredentialsGrant() throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Throws:
      java.io.IOException
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
    • getAccessTokenClientCredentialsGrant

      public OAuth2AccessToken getAccessTokenClientCredentialsGrant​(java.lang.String scope) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Throws:
      java.io.IOException
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
    • getAccessTokenClientCredentialsGrant

      public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenClientCredentialsGrant​(OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
      Start the request to retrieve the access token using client-credentials grant. The optionally provided callback will be called with the Token when it is available.
      Parameters:
      callback - optional callback
      Returns:
      Future
    • getAccessTokenClientCredentialsGrant

      public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenClientCredentialsGrant​(java.lang.String scope, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
    • createRevokeTokenRequest

      protected OAuthRequest createRevokeTokenRequest​(java.lang.String tokenToRevoke, TokenTypeHint tokenTypeHint)
    • revokeTokenAsync

      public java.util.concurrent.Future<java.lang.Void> revokeTokenAsync​(java.lang.String tokenToRevoke)
    • revokeTokenAsync

      public java.util.concurrent.Future<java.lang.Void> revokeTokenAsync​(java.lang.String tokenToRevoke, TokenTypeHint tokenTypeHint)
    • revokeToken

      public void revokeToken​(java.lang.String tokenToRevoke) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Throws:
      java.io.IOException
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
    • revokeToken

      public void revokeToken​(java.lang.String tokenToRevoke, TokenTypeHint tokenTypeHint) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException
      Throws:
      java.io.IOException
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
    • revokeToken

      public java.util.concurrent.Future<java.lang.Void> revokeToken​(java.lang.String tokenToRevoke, OAuthAsyncRequestCallback<java.lang.Void> callback)
    • revokeToken

      public java.util.concurrent.Future<java.lang.Void> revokeToken​(java.lang.String tokenToRevoke, OAuthAsyncRequestCallback<java.lang.Void> callback, TokenTypeHint tokenTypeHint)
    • createDeviceAuthorizationCodesRequest

      protected OAuthRequest createDeviceAuthorizationCodesRequest​(java.lang.String scope)
    • getDeviceAuthorizationCodes

      public DeviceAuthorization getDeviceAuthorizationCodes() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOException
      Requests a set of verification codes from the authorization server with the default scope
      Returns:
      DeviceAuthorization
      Throws:
      java.lang.InterruptedException - InterruptedException
      java.util.concurrent.ExecutionException - ExecutionException
      java.io.IOException - IOException
      See Also:
      RFC 8628
    • getDeviceAuthorizationCodes

      public DeviceAuthorization getDeviceAuthorizationCodes​(java.lang.String scope) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOException
      Requests a set of verification codes from the authorization server
      Parameters:
      scope - scope
      Returns:
      DeviceAuthorization
      Throws:
      java.lang.InterruptedException - InterruptedException
      java.util.concurrent.ExecutionException - ExecutionException
      java.io.IOException - IOException
      See Also:
      RFC 8628
    • getDeviceAuthorizationCodes

      public java.util.concurrent.Future<DeviceAuthorization> getDeviceAuthorizationCodes​(OAuthAsyncRequestCallback<DeviceAuthorization> callback)
    • getDeviceAuthorizationCodes

      public java.util.concurrent.Future<DeviceAuthorization> getDeviceAuthorizationCodes​(java.lang.String scope, OAuthAsyncRequestCallback<DeviceAuthorization> callback)
    • getDeviceAuthorizationCodesAsync

      public java.util.concurrent.Future<DeviceAuthorization> getDeviceAuthorizationCodesAsync()
    • getDeviceAuthorizationCodesAsync

      public java.util.concurrent.Future<DeviceAuthorization> getDeviceAuthorizationCodesAsync​(java.lang.String scope)
    • createAccessTokenDeviceAuthorizationGrantRequest

      protected OAuthRequest createAccessTokenDeviceAuthorizationGrantRequest​(DeviceAuthorization deviceAuthorization)
    • getAccessTokenDeviceAuthorizationGrant

      public OAuth2AccessToken getAccessTokenDeviceAuthorizationGrant​(DeviceAuthorization deviceAuthorization) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOException
      Attempts to get a token from a server. Function pollAccessTokenDeviceAuthorizationGrant(com.github.scribejava.core.model.DeviceAuthorization) is usually used instead of this.
      Parameters:
      deviceAuthorization - deviceAuthorization
      Returns:
      token
      Throws:
      java.lang.InterruptedException - InterruptedException
      java.util.concurrent.ExecutionException - ExecutionException
      java.io.IOException - IOException
      OAuth2AccessTokenErrorResponse - If OAuth2AccessTokenErrorResponse.getError() is OAuth2Error.AUTHORIZATION_PENDING or OAuth2Error.SLOW_DOWN, another attempt should be made after a while.
      See Also:
      getDeviceAuthorizationCodes()
    • getAccessTokenDeviceAuthorizationGrant

      public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenDeviceAuthorizationGrant​(DeviceAuthorization deviceAuthorization, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
    • getAccessTokenDeviceAuthorizationGrantAsync

      public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenDeviceAuthorizationGrantAsync​(DeviceAuthorization deviceAuthorization)
    • pollAccessTokenDeviceAuthorizationGrant

      public OAuth2AccessToken pollAccessTokenDeviceAuthorizationGrant​(DeviceAuthorization deviceAuthorization) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOException
      Periodically tries to get a token from a server (waiting for the user to give consent). Sync only version. No Async variants yet, one should implement async scenarios themselves.
      Parameters:
      deviceAuthorization - deviceAuthorization
      Returns:
      token
      Throws:
      java.lang.InterruptedException - InterruptedException
      java.util.concurrent.ExecutionException - ExecutionException
      java.io.IOException - IOException
      OAuth2AccessTokenErrorResponse - Indicates OAuth error.
      See Also:
      getDeviceAuthorizationCodes()