【发布时间】:2019-09-11 14:31:33
【问题描述】:
在通过重定向 URL 获得授权后尝试调用两个不同的资源时,第一个调用完成,第二个调用无法使用 "HTTP 401 Unauthorized" 刷新其令牌。
在下面的代码中,对第二个服务的调用总是失败(即使更改调用顺序或多次调用第一个服务)
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();
经过一些调试,我发现 Azure SDK 上的以下功能失败:(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;
}
}
【问题讨论】:
-
您是否已将 azure ad graph api 权限授予您的 AD 应用?
-
是的,如果我先调用图形 api,它工作正常并且对管理 api 的请求失败。第二次调用总是失败。
-
在使用第一个刷新令牌请求新的访问令牌和第二个刷新令牌时,您是否将资源更改为正确的?
-
不确定我是否关注。我运行了上面提到的代码 - 有没有我遗漏的步骤?
-
代码看起来不错,但我不确定你是否在 refreshToken() 中传递了正确的
resource?我的意思是如果你使用刷新令牌来获取资源https://management.core.windows.net/的新访问令牌,那么新的访问令牌将无法调用azure ad graph apihttps://graph.windows.net/。
标签: azure azure-devops azure-active-directory azure-java-sdk