Package org.azd.oauth
Class OAuthApi
java.lang.Object
org.azd.oauth.OAuthApi
OAuth Api class to authorize access to REST API
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic AuthorizedToken
getAccessToken
(String appSecret, String authCode, String callbackUrl) Now you use the authorization code to request an access token for the user.static String
Generate the authorization endpoint with client id, state, scope and redirection url.static AuthorizedToken
getRefreshToken
(String appSecret, String authCode, String callbackUrl) 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.static boolean
hasTokenExpired
(AuthorizedToken authorizedToken) Check if the access token has expired.
-
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 registeredstate
- 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 registeredauthCode
- URL encoded "code" provided via the code query parameter to your callback URLcallbackUrl
- 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 registeredauthCode
- URL encoded "code" provided via the code query parameter to your callback URLcallbackUrl
- callback URL registered with the app- Returns:
- AuthorizedToken object
AuthorizedToken
- Throws:
AzDException
- Default Api Exception handler.
-
hasTokenExpired
Check if the access token has expired.- Parameters:
authorizedToken
- authorized token objectAuthorizedToken
- Returns:
- True if the token has expired.
Boolean
-