Keyvault身份验证(REST API)

问题描述 投票:4回答:2

我对微软分散的文档感到有些困惑。

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

  • 应用程序ID
  • 目录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 Unauthorized”

azure azure-keyvault
2个回答
2
投票

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

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

这个网址有效,所以我猜这个令牌不对。最简单的检查方法是转到JWT.io并将令牌粘贴到那里并查看内容,如果它们与Key Vault期望的内容相匹配。可能你有不匹配。


3
投票

您需要指定要为其提供令牌的资源。

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版本。

© www.soinside.com 2019 - 2024. All rights reserved.