Azure keyvault客户端1.0.0启动客户端

时间:2017-07-02 19:28:50

标签: java azure sdk azure-keyvault

在azure Keyvault网站link

我找到了这段代码:

KeyVaultClient kvc = new KeyVaultClient(credentials);
KeyBundle returnedKeyBundle = getKey(vaultUrl, keyName);
JsonWebKey jsonKey = returnedKeyBundle.key();

但是没有解释如何获取客户端凭据,并且所有旧方法对于库版本1.0.0都无效。 我想使用应用程序ID和密码进行身份验证,但是如何?

1 个答案:

答案 0 :(得分:1)

根据我的理解,如果您知道如何在Azure AD中注册应用程序,我认为您需要以下代码。

String clientId = "<client id of your application registed on Azure AD>";
String domain = "<your talnet id>";
String secret = "<client key of your application registed on Azure AD>";
String subscription = "<your subscription id>";
AzureTokenCredentials cred = new ApplicationTokenCredentials(clientId, domain, secret, AzureEnvironment.AZURE);
KeyVaultClient kvc = new KeyVaultClient(credentials);

或者按照下图在Azure门户上的Azure AD中注册应用程序,然后执行上述操作。

enter image description here

更新:请添加azure依赖关系,如下所示

<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure</artifactId>
    <version>1.1.0</version>
</dependency>