问题描述
我想从微软Azure使用Java应用程序的使用情况和价目表信息,我才明白,我可以使用管理证书打电话到微软的Azure进行身份验证。
我得到了管理证书从.publishsettings文件,我从这里 ,但我没有看到任何可用的客户使用和价目表,答案是指ManagementClient,这不是一个我用例。我提到了这个博客,以及,这使得引用 ClientAssertionCertificate
,我没有在的。
注:我能做出REST API调用到Azure使用的用户名,密码和放大器得到使用和价目表的信息;客户端基于ID的认证机制,但我想利用这个管理证书机制,因为我的应用程序的用户可能不信任他们的凭据,此应用程序,这基于证书的机制似乎更容易从一个用户点使用。
As Gaurav said, We just only can call Usage & Rate Card API using Azure Active Directory for authentication. You can use AuthenticationContext to acquire the the access_token
as following code. You need provide client ID
and Client Secret
(key
).
private AuthenticationResult getAccessTokenFromClientCredentials()
throws Throwable {
AuthenticationContext context = null;
AuthenticationResult result = null;
ExecutorService service = null;
try {
service = Executors.newFixedThreadPool(1);
context = new AuthenticationContext(authority + tenant + "/", true,
service);
Future<AuthenticationResult> future = context.acquireToken(
"https://graph.windows.net", new ClientCredential(clientId,
clientSecret), null);
result = future.get();
} catch (ExecutionException e) {
throw e.getCause();
} finally {
service.shutdown();
}
if (result == null) {
throw new ServiceUnavailableException(
"authentication result was null");
}
return result;
}
It seems that we can't use Management certificate mechanism to call Usage & Rate Card API. Because these calling user or the service principal is a member of the Owner, Contributor or Reader role
in the Azure AD tenant for the requested subscription (see this document). I recommend you refer to this document about how to authenticate Azure Resource Management.
这篇关于如何使用基于管理证书认证作出REST API调用Azure的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!