Package org.azd.oauth

Class OAuthAccessTokenBuilder

java.lang.Object
org.azd.oauth.OAuthAccessTokenBuilder

public class OAuthAccessTokenBuilder extends Object
Provides the functionality to generate and oauth access token to call Azure DevOps Api. Note that you should have registered you application before using this.
  • Constructor Details

    • OAuthAccessTokenBuilder

      public OAuthAccessTokenBuilder()
      Instantiates a new request builder instance and sets the default values.
  • Method Details

    • buildAuthorizationEndpoint

      public String buildAuthorizationEndpoint(AuthorizationEndpoint authorizationEndpoint)
      Generate the authorization endpoint with client id, state, scope and redirection url.
      Parameters:
      authorizationEndpoint - Provide the parameters to build authorization endpoint.
      Returns:
      The authorization endpoint to authorize your app
    • getAccessToken

      public 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 AuthorizedToken getRefreshToken(String appSecret, String refreshToken, 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.
      refreshToken - URL encoded refresh token for the user.
      callbackUrl - callback URL registered with the app.
      Returns:
      AuthorizedToken object AuthorizedToken
      Throws:
      AzDException - Default Api Exception handler.
    • hasTokenExpired

      public 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