使用Postman的Azure Rest API

wnrlj8wa  于 8个月前  发布在  Postman
关注(0)|答案(1)|浏览(99)

我试着用postman从容器中获取blob,我试着从集合中做这个。以下链接:https://www.postman.com/speeding-astronaut-338068/workspace/azure-rest-api/request/13081473-85754311-416e-459a-a38d-fd37e4933bc4
首先,我去一条名为:

Get Storage Bearer Token

我在哪里可以通过发出此请求获得我的access_token:

在上面,我成功地获得了我的access_token。然后转到List Blobs路由,并使用适当的存储帐户名称和容器名称填充url

但我得到了这个错误:

<?xml version="1.0" encoding="utf-8"?>
<Error>
    <Code>AuthorizationPermissionMismatch</Code>
    <Message>This request is not authorized to perform this operation using this permission.
RequestId:606c7212-201e-0005-3583-f1ab58000000
Time:2023-09-27T20:46:55.2555893Z</Message>
</Error>

为什么即使提供了所有正确的变量,我还是会收到这个错误?我读了一些文章,比如:
https://learn.microsoft.com/en-us/answers/questions/779065/error-this-request-is-not-authorized-to-perform-th
但我无法解决它,因为错误仍然存在,
要接收我的client_id,client_secret,我遵循以下教程:
https://docs.lacework.net/onboarding/gather-the-required-azure-client-id-tenant-id-and-client-secret我还在我的容器和存储帐户中授予了对服务的读取权限

wmtdaxz3

wmtdaxz31#

如果服务主体没有执行操作所需的RBAC角色权限,则通常会发生此错误。
我注册了一个Azure AD应用程序,并添加了API权限,如下所示:

现在,我在存储账户下为上述服务主体添加了Reader角色:

我通过Postman使用相同参数使用客户端凭据流生成访问令牌:

POST https://login.microsoftonline.com/tenantId/oauth2/token
grant_type:client_credentials
client_id:appId
client_secret:secret
resource: https://storage.azure.com

回复:

当我使用这个令牌通过在REST API调用下面运行来列出blob时,我得到了像这样的相同的错误

GET https://sristorage28.blob.core.windows.net/sri?restype=container&comp=list
Authorization: Bearer <token>
x-ms-date: 2020-10-02

回复:

需要注意的是,Reader角色的存储账号容器不能执行创建、读取、删除、更新等数据操作。
解决此错误,您需要分配与存储相关的RBAC角色,如 * Storage Blob Data Contributor* 或 * Storage Blob Data Owner*。
在我的例子中,我将Storage Blob Data Contributor分配给存储账户下的服务主体,如下所示:

当我通过生成new bearertoken分配上述角色后,调用REST API时,成功得到了response,里面有blob列表:

GET https://sristorage28.blob.core.windows.net/sri?restype=container&comp=list
Authorization: Bearer <token>
x-ms-date: 2020-10-02

回复:

如果错误仍然存在,请尝试使用v2.0 token端点生成访问令牌,正如我之前在此SO线程中提到的那样。

相关问题