使用 AAD 身份验证的 Azure 存储列表 Blobs - 受众验证失败。

问题描述 投票:0回答:1

使用Postman,得到一个Bearer令牌,成功列出存储账户和资源组。在同一个集合中,尝试在容器中列出Blobs,得到 "Audience validation failed. Audience did not match"。如果能帮助诊断这个错误,将非常感谢。enter image description here

azure rest authentication azure-storage-blobs
1个回答
0
投票

如果要使用Azure AD访问令牌来访问Azure blob rest API,我们需要为Azure RABC角色分配(存储Blob数据所有者, 存储Blob数据贡献者储存Blob数据读取器)到服务委托人或AD用户。更多详情,请参考 文件

例如(我使用服务委托人 )1.创建一个服务委托人,并为sp分配Azure RABC角色。

az login
az account set --subscription "<your subscription id>"
# it will assign Storage Blob Data Reader to the sp at storage accountlevel
az ad sp create-for-rbac -n "mysample" --role Storage Blob Data Reader --scopes <the resource id of storage account>

enter image description here

  1. 获取AD访问令牌
POST /<your sp tenant id>/oauth2/token HTTP/1.1
Host: login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded

grant_type =client_credentials
&client_id=<your sp appId>
&client_secret=<your sp password>k
&resource=https://storage.azure.com/
  1. 列表膨胀物
GET https://myaccount.blob.core.windows.net/mycontainer?restype=container&comp=list

x-ms-version: 2017-11-09
Authorization: Bearer <access token>

enter image description here

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