【发布时间】:2018-10-20 10:01:59
【问题描述】:
我有一个 Azure 帐户,现在我正在尝试在控制台应用程序中获取令牌以管理资源(即创建资源组等):
string userName = "xyz@gmail.com";
string password = "XXXXXXXXX";
string directoryName = "xyzgmail.onmicrosoft.com";
string clientId = "guid-of-registered-application-xxx";
var credentials = new UserPasswordCredential(userName, password);
var authenticationContext = new AuthenticationContext("https://login.windows.net/" + directoryName);
var result = await authenticationContext.AcquireTokenAsync("https://management.core.windows.net/", clientId, credentials);
在 AcquireTokenAsync 通话中我有
Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException: 'accessing_ws_metadata_exchange_failed: 访问 WS 元数据交换 失败'
有人可以帮忙吗?
更新:我如何尝试在新创建的用户下创建资源组
var jwtToken = result.AccessToken;
string subscriptionId = "XX-XX-XX-YY-YY-YY";
var tokenCredentials = new TokenCredentials(jwtToken);
var client = new ResourceManagementClient(tokenCredentials);
client.SubscriptionId = subscriptionId;
var rgResponse = await client.ResourceGroups.CreateOrUpdateWithHttpMessagesAsync("myresgroup77777",
new ResourceGroup("East US"));
这里我遇到了另一个异常
'带有对象 ID 的客户端 'newaduser@xyzgmail.onmicrosoft.com' 'aaa-aaa-aaa-aaa' 无权执行操作 'Microsoft.Resources/subscriptions/resourcegroups/write' 超出范围 '/subscriptions/XX-XX-XX-YY-YY-YY/resourcegroups/myresgroup77777'。'
【问题讨论】:
-
你有链接到你看到它以这种方式使用的资源吗? I don't even see an overload that matches what you are doing
-
您是否为用户分配了角色?执行
Windows Azure Service Management API的权限被授予假定登录用户身份的应用程序。但是,该用户必须是有权在订阅中创建资源组的角色。尝试将订阅级别的内置Contributor角色分配给该用户。 -
@GauravMantri 太棒了!有用!只是一个小问题,我可以通过初始用户(即所有者)登录而不是火化新用户吗?
-
你应该可以这样做。我试图查找您遇到的第一个错误,但找不到任何关于此的结论。让我发表我的评论作为答案。
标签: c# azure azure-active-directory