从 Azure Web App 托管服务标识创建资源组

Creating resource groups from Azure Web App Managed Service Identity

我正在尝试使用 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 应用程序的托管服务标识。我制作了这个 Azure 订阅的 Web 应用 "Owner"。

当我执行此代码时,我不断收到此异常

Exception: The access token has been obtained from wrong audience or resource ’https://management.core.windows.net'. It should exactly match (including forward slash) with one of the allowed audiences ‘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);

如何设置此受众或资源或者我做错了什么?

How to set this audience or resource or what am i doing wrong?

我也可以在我这边重现这个问题。看来是SDK的问题。您可以向 Azure SDK github issue.

举报

更新:

根据issue-4090,1.7版本已经修复,发布后可以再测试