我正在尝试编写一个独立程序来使用 Azure 资源管理器 .Net 库访问 Azure 资源组详细信息。根据文档,它需要在每个资源管理器请求中使用 Azure AD 身份验证和令牌。所以我在 AD 中创建了一个 Web 应用程序并配置了密钥并使用它来生成令牌。
但是即使我在请求中将此令牌作为承载传递,下面的代码也失败了。
m_resourceClient = new ResourceManagementClient(connection.GetCredentials());
m_resourceClient.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", connection.GetAccessToken());
***ResourceGroupGetResult resourceGroupList = m_resourceClient.ResourceGroups.Get("PraveenTest")*** ;
错误信息:
AuthorizationFailed: The client '5919f7f9-####-####-####-074456eba98c' with object id '5919f7f9-####-####-####-074456eba98c' does not have authorization to perform action
'Microsoft.Resources/subscriptions/resourcegroups/read' over scope '/subscriptions/1f94c869-####-####-####-055e8ae15be3/resourcegroups/TestGroup'.