Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,28 @@ public static AzureADToken getTokenUsingRefreshToken(String clientId, String ref
return getTokenCall(authEndpoint, qp.serialize());
}

/**
* gets Azure Active Directory token using refresh token
*
* @param authEndpoint the OAuth 2.0 token endpoint associated with the user's directory
* (obtain from Active Directory configuration)
* @param clientId the client ID (GUID) of the client web app obtained from Azure Active Directory configuration
* @param refreshToken the refresh token
* @return {@link AzureADToken} obtained using the refresh token
* @throws IOException throws IOException if there is a failure in connecting to Azure AD
*/
public static AzureADToken getTokenUsingRefreshToken(String authEndpoint, String clientId, String refreshToken)
throws IOException
{
QueryParams qp = new QueryParams();
qp.add("grant_type", "refresh_token");
qp.add("refresh_token", refreshToken);
if (clientId != null) qp.add("client_id", clientId);
log.debug("AADToken: starting to fetch token using refresh token for client ID " + clientId );

return getTokenCall(authEndpoint, qp.serialize());
}

/**
* gets Azure Active Directory token using the user's username and password. This only
* works if the identity can be authenticated directly by microsoftonline.com. It will likely
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
public class RefreshTokenBasedTokenProvider extends AccessTokenProvider {

private static final Logger log = LoggerFactory.getLogger("com.microsoft.azure.datalake.store.oauth2.RefreshTokenBasedTokenProvider");
private final String clientId, refreshToken;
private final String authEndpoint, clientId, refreshToken;

/**
* constructs a token provider based on the refresh token provided
*
* @param refreshToken the refresh token
*/
public RefreshTokenBasedTokenProvider(String refreshToken) {
this.authEndpoint = null;
this.clientId = null;
this.refreshToken = refreshToken;
}
Expand All @@ -36,6 +37,7 @@ public RefreshTokenBasedTokenProvider(String refreshToken) {
* @param refreshToken the refresh token
*/
public RefreshTokenBasedTokenProvider(String clientId, String refreshToken) {
this.authEndpoint = null;
this.clientId = clientId;
this.refreshToken = refreshToken;
}
Expand All @@ -47,6 +49,7 @@ public RefreshTokenBasedTokenProvider(String clientId, String refreshToken) {
* @param refreshToken the refresh token
*/
public RefreshTokenBasedTokenProvider(String clientId, RefreshTokenInfo refreshToken) {
this.authEndpoint = null;
this.clientId = clientId;
this.refreshToken = refreshToken.refreshToken;
if (refreshToken.accessToken != null &&
Expand All @@ -58,9 +61,25 @@ public RefreshTokenBasedTokenProvider(String clientId, RefreshTokenInfo refreshT
}
}

/**
* constructs a token provider based on the refresh token provided
*
* @param authEndpoint the OAuth 2.0 token endpoint associated with the user's directory
* (obtain from Active Directory configuration)
* @param clientId the client ID (GUID) of the client web app obtained from Azure Active Directory configuration
* @param refreshToken the refresh token
*/
public RefreshTokenBasedTokenProvider(String authEndpoint, String clientId, String refreshToken) {
this.authEndpoint = authEndpoint;
this.clientId = clientId;
this.refreshToken = refreshToken;
}

@Override
protected AzureADToken refreshToken() throws IOException {
log.debug("AADToken: refreshing refresh-token based token");
return AzureADAuthenticator.getTokenUsingRefreshToken(clientId, refreshToken);
if (authEndpoint == null)
return AzureADAuthenticator.getTokenUsingRefreshToken(clientId, refreshToken);
return AzureADAuthenticator.getTokenUsingRefreshToken(authEndpoint, clientId, refreshToken);
}
}