Class OAuthUtils

java.lang.Object
org.apache.drill.exec.store.http.oauth.OAuthUtils

public class OAuthUtils extends Object
  • Constructor Details

    • OAuthUtils

      public OAuthUtils()
  • Method Details

    • getPostRequest

      public static okhttp3.RequestBody getPostRequest(CredentialsProvider credentialsProvider, String authorizationCode, String callbackURL)
      Crafts a POST request to obtain an access token.
      Parameters:
      credentialsProvider - A credential provider containing the clientID, clientSecret and authorizationCode
      authorizationCode - The authorization code from the OAuth2.0 enabled API
      callbackURL - The callback URL. For our purposes this is obtained from the incoming Drill request as it all goes to the same place.
      Returns:
      A Request Body to obtain an access token
    • getPostRequestForTokenRefresh

      public static okhttp3.RequestBody getPostRequestForTokenRefresh(CredentialsProvider credentialsProvider, String refreshToken)
      Crafts a POST request for refreshing an access token when a refresh token is present.
      Parameters:
      credentialsProvider - A credential provider containing the clientID, clientSecret and refreshToken
      refreshToken - The refresh token
      Returns:
      A Request Body with the correct parameters for obtaining an access token
    • buildAccessTokenURL

      public static String buildAccessTokenURL(CredentialsProvider credentialsProvider)
      Helper method for building the access token URL.
      Parameters:
      credentialsProvider - The credentialsProvider containing all the OAuth pieces.
      Returns:
      The URL string for obtaining an Auth Code.
    • getAccessTokenRequest

      public static okhttp3.Request getAccessTokenRequest(CredentialsProvider credentialsProvider, String authenticationCode, String callbackURL)
      Crafts a POST request to obtain an access token. This method should be used for the initial call to the OAuth API when you are exchanging the authorization code for an access token.
      Parameters:
      credentialsProvider - The credentialsProvider containing the client_id, client_secret, and auth_code.
      authenticationCode - The authentication code from the API.
      Returns:
      A request to obtain the access token.
    • getAccessTokenRequestFromRefreshToken

      public static okhttp3.Request getAccessTokenRequestFromRefreshToken(CredentialsProvider credentialsProvider, String refreshToken)
      Crafts a POST request to obtain an access token. This method should be used for the additional calls to the OAuth API when you are refreshing the access token. The refresh token must be populated for this to be successful.
      Parameters:
      credentialsProvider - The credential provider containing the client_id, client_secret, and refresh token.
      refreshToken - The OAuth2.0 refresh token
      Returns:
      A request to obtain the access token.
    • getOAuthTokens

      public static Map<String,String> getOAuthTokens(okhttp3.OkHttpClient client, okhttp3.Request request)
      This function is called in after the user has obtained an OAuth Authorization Code. It returns a map of any tokens returned which should be an access_token and an optional refresh_token.
      Parameters:
      client - The OkHTTP3 client.
      request - The finalized Request to obtain the tokens. This request should be a POST request containing a client_id, client_secret, authorization code, and grant type.
      Returns:
      a Map of any tokens returned.