When trying to call two different resources after being authorised through the redirect URL, the first call finishes and the second call fails to refresh its token with "HTTP 401 Unauthorized"
.
In the code below the call to the second service always fails (even when changing the order of the calls or calling the first service multiple times)
ApplicationTokenCredentials applicationTokenCredentials = new ApplicationTokenCredentials(clientId, domain, secret, AzureEnvironment.AZURE);
DelegatedTokenCredentials delegatedTokenCredentials = new DelegatedTokenCredentials(applicationTokenCredentials, redirectUrl, code);
Azure.Authenticated azureAuth = Azure.authenticate(delegatedTokenCredentials);
//First call - resource : https://management.core.windows.net/
azureAuth.subscriptions().list();
//Second call - resource : https://graph.windows.net/
azureAuth.servicePrincipals().list();
After some debugging i found that the following function on the Azure SDK fails : (com.microsoft.azure.credentials.RefreshTokenClient)
AuthenticationResult refreshToken(String tenant, String clientId, String resource, String refreshToken, boolean isMultipleResourceRefreshToken) {
try {
RefreshTokenResult result = service.refreshToken(tenant, clientId, "refresh_token", resource, refreshToken)
.toBlocking().single();
if (result == null) {
return null;
}
return new AuthenticationResult(
result.tokenType,
result.accessToken,
result.refreshToken,
result.expiresIn,
null,
null,
isMultipleResourceRefreshToken);
} catch (Exception e) {
return null;
}
}