无法获取 Azure 成本消耗 api 的 Azure 范围

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

我需要为 php 项目使用 azure conspiration api。但我完全搞乱了范围。

我遵循的步骤:

  1. 注册应用并获取应用ID。
  2. 创建客户端密钥
  3. curl -X POST -d 'grant_type=client_credentials&client_id=86abe145-****-****-****-*******&client_secret=Ymm7Q~xp_****************&resource=https%3A%2F%2Fmanagement.azure.com%2F' https://login.microsoftonline.com/09c409ff-*****-******-******-fa0/oauth2/token

并返回过期的访问令牌。 但是当我调用 api 来获取价格表或使用详细信息的数据时,它给了我

{"error":{"code":"AuthorizationFailed","message":"The client 'cd1bfd00-561d-****-af29-*********' with object id 'cd1bfd00-561d-4d84-af29-********' does not have authorization to perform action 'Microsoft.Consumption/usageDetails/read' over scope '/subscriptions/*******-f489-47e8-****-*********' or the scope is invalid. If access was recently granted, please refresh your credentials."}}

{scope} 需要传入什么值。我在注册的应用程序中创建了一个名为 hub-app 的范围,并获得管理员和用户的同意,并通过了它。

api://<client-id>/hub-app
。但没有任何作用。 如果有人使用消费API,请帮忙。

谢谢!

azure azure-devops azure-api-management azure-rest-api azure-billing-api
2个回答
3
投票

您似乎只是在 Azure AD 中创建了一个应用程序,并且没有为其分配任何 Azure RBAC 角色。这就是您收到此错误的原因。

要解决此问题,请在订阅级别将

Billing Reader
Reader
角色分配给您的应用程序。请参阅此链接以使用 Azure 门户分配角色:https://learn.microsoft.com/en-us/azure/role-based-access-control/role-assignments-portal?tabs=current


0
投票

该视频有分步过程,也许可以看看 - https://www.youtube.com/watch?v=eRTp-89DAg8

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