我需要为 php 项目使用 azure conspiration api。但我完全搞乱了范围。
我遵循的步骤:
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 AD 中创建了一个应用程序,并且没有为其分配任何 Azure RBAC 角色。这就是您收到此错误的原因。
Billing Reader
或 Reader
角色分配给您的应用程序。请参阅此链接以使用 Azure 门户分配角色:https://learn.microsoft.com/en-us/azure/role-based-access-control/role-assignments-portal?tabs=current。
该视频有分步过程,也许可以看看 - https://www.youtube.com/watch?v=eRTp-89DAg8