如果要使用 Azure AD 访问令牌访问 Azure blob rest API,我们需要为服务主体或 AD 用户分配 Azure RABC 角色(存储 Blob 数据所有者、存储 Blob 数据贡献者或存储 Blob 数据读取者)。更多详情请参考文档
例如(我使用服务主体) 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>
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/
GET https://myaccount.blob.core.windows.net/mycontainer?restype=container&comp=list
x-ms-version: 2017-11-09
Authorization: Bearer <access token>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句