2

我正在尝试使用 java 应用程序从 Microsoft Azure 获取使用情况和价目表信息,我了解到我可以使用管理证书进行身份验证以调用 Microsoft Azure。

我从此处获得的 .publishsettings 文件中获得了管理证书

但是,在 中AuthenticationContext,我没有看到任何使用此证书来获取进行使用和速率 API 调用所需的访问令牌的方法。

我尝试参考这个答案,但我没有看到任何可用于使用和价目表的客户端,并且答案指的是 ManagementClient,这不是我的用例。我也参考了这个博客,它引用了,我在java 库中ClientAssertionCertificate没有看到adal 。

注意:我可以使用基于用户名、密码和客户端 ID 的身份验证机制对 Azure 进行 REST API 调用,以获取使用情况和价目表信息,但我想利用这种管理证书机制,因为我的应用程序的用户可能不会用他们的凭据信任这个应用程序,从用户的角度来看,这种基于证书的机制似乎更容易使用。

4

2 回答 2

1

但是,在 AuthenticationContext 中,我没有看到任何使用此证书来获取进行使用和评估 API 调用所需的访问令牌的方法。

我也参考了这个博客,它引用了 ClientAssertionCertificate ,我在 adal 的 java 库中没有看到它。

正如 Gaurav 所说,我们只能使用 Azure Active Directory 调用 Usage & Rate Card API 进行身份验证。您可以使用 AuthenticationContext 获取access_token如下代码。您需要提供client IDClient 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;
    }

注意:我可以使用基于用户名、密码和客户端 ID 的身份验证机制对 Azure 进行 REST API 调用以获取使用情况和价目表信息,......

看来我们不能使用管理证书机制来调用 Usage & Rate Card API。因为这些调用用户或服务主体是Owner, Contributor or Reader role请求订阅的 Azure AD 租户中的成员(请参阅此文档)。我建议您参考此文档了解如何对Azure 资源管理进行身份验证

于 2015-10-08T02:35:39.240 回答
1

简单的答案是您不能使用管理证书来使用 Billing API。计费 API 本质上是使用 Azure AD 令牌的较新 API 的一部分。

管理证书只能用于Service Management APIs.

于 2015-10-05T19:04:49.660 回答