2017-05-05 186 views
1

我对微软分散的文档有点困惑。Keyvault身份验证(REST API)

我已经创建了一个应用程序(https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal),这意味着我现在有:

  • 应用ID
  • 重点
  • 目录编号

我已经到Azure中KeyVault门户网站和我已授予应用程序的权限。

出于测试目的,我试图通过CURL运行测试。我使用该算法的基础是下面的Microsoft网页(https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-service-to-service#request-an-access-tokenhttps://docs.microsoft.com/en-us/rest/api/#create-the-request

所以,我做的第一件事就是通过下面的调用获取令牌:

curl -d "grant_type=client_credentials&client_id=<removed_for_security>&client_secret=<removed_for_security>" https://login.microsoftonline.com/<removed_for_security>/oauth2/token 

这将返回一个令牌。

然后我(尝试)使用该令牌如下:

curl -H "Authorization: Bearer <removed_for_security>” -vv https://<removed_for_security>.vault.azure.net/secrets/<removed_for_security>/<removed_for_security> 

我没有得到任何内容,则只需“HTTP/1.1 401未经授权”

回答

2

好了,我可以确认该请求你所做的是有效的,大多数情况下,你忘记了API版本,但问题不在于API版本(它会告诉你这一点)。

https://xxx.vault.azure.net/secrets/xxx/?api-version=2015-06-01 

此网址的作品,所以我猜测令牌是不正确的。检查最简单的方法是前往JWT.io并粘贴令牌并查看内容,如果它们与密钥保管库期望的内容相匹配。可能你有一个不匹配。

+0

是。我忘了API版本。 –

+0

很奇怪,当我删除API版本时,它特意告诉我,我忘了指定API版本......很高兴知道它的工作原理@LittleCode – 4c74356b41

0

您需要指定您正在请求令牌的资源。

curl -d "grant_type=client_credentials&client_id=<removed_for_security>&client_secret=<removed_for_security>&resource=https://vault.azure.net" https://login.microsoftonline.com/<removed_for_security>/oauth2/token 

并且还添加了api版本。