授权 Azure AD 应用程序访问 RateCard API

Authorize Azure AD application to access RateCard API

自从 Azure OAuth 2 发生变化后,我遇到了一个错误:

The client 'xxx' with object id 'xxx' does not have authorization to perform action 'Microsoft.Commerce/RateCard/read' over scope '/subscriptions/xxx'.

我已关注 role-based assignment instructions,为我的申请添加了一个 Reader 角色到 DefaultResourceGroupResource

我还在我的应用程序清单的 appRoles 部分添加了一个 Admin 角色。

并添加所有可能的应用权限:

为了调用 RateCard API,我检索了一个令牌:

curl -X POST -H "Content-Type: application/x-www-form-urlencoded" "https://login.windows.net/xxx.onmicrosoft.com/oauth2/token" -d "grant_type=client_credentials&client_id=xxx&client_secret=xxx"

我在我的请求中使用了它:

curl -H "Authorization: Bearer <token>" "https://management.azure.com/subscriptions/xxxproviders/Microsoft.Commerce/RateCard?api-version=2015-06-01-preview&$filter=OfferDurableId eq 'MS-AZR-0003P' and Currency eq 'USD' and Locale eq 'en-US' and RegionInfo eq 'US'"

但我仍然有这个错误。

我应该怎么做才能将此授权添加到我的应用程序中?

这里是我的应用程序权限的一些屏幕截图:

I've followed the role-based assignment instructions, added a Reader role for my application to the DefaultResourceGroupResource.

与其授予对单个资源组的 Reader 角色权限,不如尝试授予订阅级别的相同权限。

您可以做的另一件事是在您的订阅中创建一个具有以下权限的自定义角色

Microsoft.Commerce/RateCard/read 
Microsoft.Commerce/UsageAggregates/read

然后您可以将此自定义角色分配给您的应用程序。

在与 Azure 支持人员短暂通话后,他们告诉我这种权限无法通过门户处理,必须在 PowerShell 中完成。

所以我不得不下载一个 Windows 10 虚拟机到 运行 :

登录到 Azure 帐户:

Login-AzureRmAccount

添加权限:

New-AzureRMRoleAssignment -ServicePrincipalName "<my-app-id>" -RoleDefinitionName "Reader" -Scope "/subscriptions/<my-subscription-id>"

检查权限分配是否正确:

Get-AzurermRoleAssignment  -ServicePrincipalName "<my-app-id>"