【发布时间】:2018-02-22 14:18:11
【问题描述】:
我正在尝试使用 MS Bot 框架构建一个 Bot,并且该 bot 作为 Azure Web 应用程序托管。我添加了使用Microsoft.Azure.Management.Fluent API 创建资源组的代码
AzureCredentialsFactory f = new AzureCredentialsFactory();
var msi = new MSILoginInformation(MSIResourceType.AppService);
var msiCred = f.FromMSI(msi, AzureEnvironment.AzureGlobalCloud);
var azureAuth = Azure.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.BodyAndHeaders)
.Authenticate(msiCred);
var azure = azureAuth.WithSubscription(subscription);
var resourceGroup = azure.ResourceGroups.Define(rg)
.WithRegion(Region.EuropeWest)
.Create();
此代码利用了 Web 应用的托管服务标识。我已将此 Web 应用设为 Azure 订阅的“所有者”。
当我执行此代码时,我不断收到此异常
异常:访问令牌已从错误的受众或资源“https://management.core.windows.net”获取。它应该与允许的受众之一“https://management.core.windows.net/”、“https://management.azure.com/”完全匹配(包括正斜杠)。
我从不手动设置受众或资源,也没有看到有关如何执行此操作的任何选项。
当我更改代码以使用我自己创建的服务主体时,它工作得很好
ServicePrincipalLoginInformation loginInfo = new ServicePrincipalLoginInformation()
{
ClientId = _clientId,
ClientSecret = _clientSecret
};
var credentials = new AzureCredentials(loginInfo, _tenantId, AzureEnvironment.AzureGlobalCloud);
var azureAuth = Azure.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.BodyAndHeaders)
.Authenticate(credentials);
如何设置此受众或资源或我做错了什么?
【问题讨论】:
标签: c# azure azure-management-api azure-managed-identity