密钥库身份验证(REST API)

Lit*_*ode 4 azure azure-keyvault

我对微软分散的文档有点困惑。

我创建了一个应用程序(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
Run Code Online (Sandbox Code Playgroud)

这将返回一个令牌。

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

curl -H "Authorization: Bearer <removed_for_security>” -vv https://<removed_for_security>.vault.azure.net/secrets/<removed_for_security>/<removed_for_security>
Run Code Online (Sandbox Code Playgroud)

我没有返回任何内容,只有“HTTP/1.1 401 Unauthorized”

小智 5

您需要指定要为其请求令牌的资源。

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
Run Code Online (Sandbox Code Playgroud)

并添加api版本。