【发布时间】:2017-03-20 13:34:14
【问题描述】:
我正在尝试使用 C# .NET SDK 配置我的一个 Web 应用程序。我想使用 Azure AD 应用程序而不是管理证书(我之前已经开始使用)。
我有以下代码:
var subscriptionId = "<subscription-guid>";
var appId = "<app-guid>";
var appKey = "<app-key>";
var tenantId = "<tenant-guid>";
var context = new AuthenticationContext("https://login.windows.net/" + tenantId);
ClientCredential clientCredential = new ClientCredential(appId, appKey);
var tokenResponse = context.AcquireTokenAsync("https://management.core.windows.net/", clientCredential).Result;
var accessToken = tokenResponse.AccessToken;
var myWebspace = "<my-webspace>";
var myWebsite = "<my-website>";
var client = new WebSiteManagementClient(new TokenCloudCredentials(subscriptionId, accessToken));
var config = client.WebSites.GetConfigurationAsync(myWebspace, myWebsite).Result;
...但它在最后一行抛出以下错误:
Microsoft.WindowAzure.CloudException
ForbiddenError: The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription.
可能出了什么问题?我已创建应用程序并授予它以下权限:
Windows Azure 服务管理
应用程序权限:0
委派权限:1
以组织用户身份访问 Azure 服务管理(预览版)
Windows Azure 活动目录
应用程序权限:0
委派权限:1
登录并阅读用户资料
提前致谢
克里斯
【问题讨论】:
-
请查看此线程以了解您收到错误的可能原因:stackoverflow.com/questions/35190866/…
标签: c# .net azure azure-active-directory azure-sdk-.net