"AuthorizationFailed" 请求 Azure 指标数据时
"AuthorizationFailed" when requesting Azure metrics data
我正在尝试使用 Active Directory 应用程序注册访问我的本地主机 (http://localhost:8100) 资源的 Ionic webapp 中的指标数据。
我的管理员为我的本地主机应用程序创建了一个新的应用程序注册,可以请求一个新的 Bearer 访问令牌。
收到访问令牌后,我想让应用程序使用此访问令牌来请求指标数据。
我的网络应用程序用来调用指标(http GET 请求)的网址之一是:
"https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resourcegroup_name}/providers/Microsoft.Compute/virtualMachines/{VirtualMachine_name}/providers/microsoft.insights/metrics?api-version=2018-01-01&metricnames=Percentage%20CPU×pan=2018-10-16T03:00:00Z/2018-10-17T03:00:00Z"
与 headers:
Authorization: {Bearer access_token},
Content-Type: 'application/json'
不幸的是,发送此 get 请求后 returns 错误 "AuthorizationFailed"
(http 错误代码 403),消息为:
"The client '{client id}' with object id '{same as client id}' does not have authorization to perform action 'microsoft.Insights/metrics/read' over scope '/subscriptions/{subscription_id}/resourceGroups/{resourcegroup_name}/providers/Microsoft.Compute/virtualMachines/{VirtualMachine_name}/providers/microsoft.Insights'."
这里出了什么问题?
我解决了这个问题,因为我注意到在 Active Directory 中注册的应用程序没有授予角色。
我通过导航至 subscription
window 然后导航至 Access control (IAM)
选项卡授予此应用程序角色。在此选项卡中,我添加了在 Active Directory 应用程序注册中声明并授予角色 reader
的应用程序。
自从我保存了设置后,AuthorizationFailed
错误就再也没有发生过。
我正在尝试使用 Active Directory 应用程序注册访问我的本地主机 (http://localhost:8100) 资源的 Ionic webapp 中的指标数据。
我的管理员为我的本地主机应用程序创建了一个新的应用程序注册,可以请求一个新的 Bearer 访问令牌。
收到访问令牌后,我想让应用程序使用此访问令牌来请求指标数据。
我的网络应用程序用来调用指标(http GET 请求)的网址之一是:
"https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resourcegroup_name}/providers/Microsoft.Compute/virtualMachines/{VirtualMachine_name}/providers/microsoft.insights/metrics?api-version=2018-01-01&metricnames=Percentage%20CPU×pan=2018-10-16T03:00:00Z/2018-10-17T03:00:00Z"
与 headers:
Authorization: {Bearer access_token},
Content-Type: 'application/json'
不幸的是,发送此 get 请求后 returns 错误 "AuthorizationFailed"
(http 错误代码 403),消息为:
"The client '{client id}' with object id '{same as client id}' does not have authorization to perform action 'microsoft.Insights/metrics/read' over scope '/subscriptions/{subscription_id}/resourceGroups/{resourcegroup_name}/providers/Microsoft.Compute/virtualMachines/{VirtualMachine_name}/providers/microsoft.Insights'."
这里出了什么问题?
我解决了这个问题,因为我注意到在 Active Directory 中注册的应用程序没有授予角色。
我通过导航至 subscription
window 然后导航至 Access control (IAM)
选项卡授予此应用程序角色。在此选项卡中,我添加了在 Active Directory 应用程序注册中声明并授予角色 reader
的应用程序。
自从我保存了设置后,AuthorizationFailed
错误就再也没有发生过。