如何从Azure Active Directory密钥创建AlertsClient?

时间:2016-11-03 17:23:05

标签: powershell azure azure-active-directory azure-management-api

我有一个ASP.NET应用程序,我正在尝试连接到Azure Monitoring API,但不断收到以下异常。我尝试关注如何将角色添加到我的应用程序服务主体(或其他东西)的powershell教程,但似乎没有任何工作,我不确定我是否需要这样做:

  

ForbiddenError:服务器无法验证请求。校验   证书有效并与此相关联   订阅。

代码:

var cred = new ClientCredential(clientId, secret);

var context = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(string.Format(
                login,
                tenantId));

var task = context
                .AcquireTokenAsync(apiEndpoint, cred);

task.Wait();

var result = task.Result;

var subCreds = new Microsoft.Azure.TokenCloudCredentials(subscriptionId, result.AccessToken);  //good AccessToken at this point

var alertsClient = new Microsoft.WindowsAzure.Management.Monitoring.Alerts.AlertsClient(subCreds);

var t = c.Incidents.ListActiveForSubscriptionAsync(new System.Threading.CancellationToken());
t.Wait();  //exception at this point

0 个答案:

没有答案