【问题标题】:Azure Resource manager .Net API fails to get Resource groupAzure 资源管理器 .Net API 无法获取资源组
【发布时间】:2015-06-22 21:17:52
【问题描述】:

我正在尝试编写一个独立程序来使用 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'.

【问题讨论】:

    标签: azure-resource-manager


    【解决方案1】:

    您的不记名令牌有效,但您还需要授予您的应用程序访问资源组的权限。

    您可以使用以下 PowerShell 命令执行此操作:

    New-AzureRmRoleAssignment 
       -ObjectId '5919f7f9-####-####-####-074456eba98c' `
       -ResourceGroupName TestGroup `
       -RoleDefinitionName Reader
    

    如果您使用的 Azure PowerShell 版本 New-AzureRoleAssignment。

    我建议 Dushyant Gill's blog post 对 ARM 请求进行身份验证。

    【讨论】:

    • 非常感谢 BenV。我是 Azure 的新手。您的建议已解决问题。
    • 我试过这个,但是当我执行这个命令时,我在提示符中再次遇到同样的错误。
    • 更新:在 MS Azure Powershell 1.0.1 版中,New-AzureRoleAssignment 现在是 New-AzureRmRoleAssignment
    • 拯救了我的一天!!在 Azure 门户中尝试相同的方法无效。使用 PowerShell 没有问题
    • 对象ID到底是什么?
    猜你喜欢
    • 2018-09-13
    • 1970-01-01
    • 1970-01-01
    • 2016-12-23
    • 2014-05-21
    • 1970-01-01
    • 1970-01-01
    • 2016-04-10
    相关资源
    最近更新 更多