【问题标题】:Even without passing a connection string to AzureServiceTokenProvider, i get Must contain 'TenantId' attribute and it must not be empty error即使没有将连接字符串传递给 AzureServiceTokenProvider,我也会得到 Must contains 'TenantId' attribute and it must not be empty 错误
【发布时间】:2022-01-05 01:54:14
【问题描述】:

在我的代码中,我尝试使用托管标识从 Azure KeyVault 中检索机密。

var azureServiceTokenProvider = new AzureServiceTokenProvider();

var keyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));

var certSecret = 等待 keyVaultClient.GetSecretAsync(keyVaultUrl, keyVaultCertParam);

此代码对我来说在本地有效,因为我还授予了我的个人帐户对 AKV 的访问权限。但是,当我尝试从具有托管标识的 VM 运行它时,我得到 Connection string RunAs=App;AppId={myMSIID} is not valid。必须包含“TenantId”属性并且不能为空。 在 Microsoft.Azure.Services.AppAuthentication.AzureServiceTokenProviderFactory.ValidateAttribute(Dictionary`2 connectionSettings, String attribute, String connectionString)。

如果根本没有传递连接字符串,为什么它会要求提供tenantid,我很困惑。

【问题讨论】:

    标签: .net azure azure-active-directory azure-managed-identity


    【解决方案1】:

    您的 VM 是否有可能设置了 AzureServicesAuthConnectionString 环境变量?这是可以指定连接字符串的另一种方式。此外,根据连接字符串错误,您似乎使用的是旧版本的 AppAuth,因为指定的连接字符串不需要租户 ID。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-17
      • 2018-09-28
      • 1970-01-01
      • 2020-05-15
      • 1970-01-01
      • 2017-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多