Package org.azd.oauth

Class OAuthApi

java.lang.Object
org.azd.oauth.OAuthApi

public class OAuthApi extends Object
OAuth Api class to authorize access to REST API
  • Constructor Details

    • OAuthApi

      public OAuthApi()
      Default constructor
  • Method Details

    • getAuthorizationEndpoint

      public static String getAuthorizationEndpoint(String clientId, String state, List<VsoScope> scope, String redirectUrl)
      Generate the authorization endpoint with client id, state, scope and redirection url.
      Parameters:
      clientId - The ID assigned to your app when it was registered
      state - Can be any value. Typically, a generated string value that correlates the callback with its associated authorization request.
      scope - Scopes registered with the app. Space separated.
      redirectUrl - Callback URL for your app. Must exactly match the URL registered with the app.
      Returns:
      The authorization endpoint to authorize your app
      See Also:
    • getAccessToken

      public static AuthorizedToken getAccessToken(String appSecret, String authCode, String callbackUrl) throws AzDException
      Now you use the authorization code to request an access token for the user. Your service must make a service-to-service HTTP request to Azure DevOps Services.
      Parameters:
      appSecret - URL encoded client secret acquired when the app was registered
      authCode - URL encoded "code" provided via the code query parameter to your callback URL
      callbackUrl - callback URL registered with the app
      Returns:
      AuthorizedToken object AuthorizedToken
      Throws:
      AzDException - Default Api Exception handler.
    • getRefreshToken

      public static AuthorizedToken getRefreshToken(String appSecret, String authCode, String callbackUrl) throws AzDException
      If a user's access token expires, you can use the refresh token that they acquired in the authorization flow to get a new access token.
      Parameters:
      appSecret - URL encoded client secret acquired when the app was registered
      authCode - URL encoded "code" provided via the code query parameter to your callback URL
      callbackUrl - callback URL registered with the app
      Returns:
      AuthorizedToken object AuthorizedToken
      Throws:
      AzDException - Default Api Exception handler.
    • hasTokenExpired

      public static boolean hasTokenExpired(AuthorizedToken authorizedToken)
      Check if the access token has expired.
      Parameters:
      authorizedToken - authorized token object AuthorizedToken
      Returns:
      True if the token has expired. Boolean