连接到中国Azure的KeyVault

发布于 2025-01-20 18:59:12 字数 967 浏览 1 评论 0原文

我将此代码用于 Azure KeyVault 服务,它与常规 Azure 配合良好

ClientSecretCredential clientCredential = new(options.KeyVaultTenantId, options.KeyVaultClientId, options.KeyVaultClientSecret);
KeyVaultCertificateWithPolicy rootCertificate = new CertificateClient(vaultUri, _clientCredential).GetCertificate(_rootCertificateId).Value;

,但我需要连接到 Azure 中国。代码失败并显示消息:

AADSTS90002:找不到租户“xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”。 检查以确保您拥有正确的租户 ID 并登录到正确的云。 请咨询您的订阅管理员,如果有,则可能会发生这种情况 租户没有有效订阅

,但我不知道在哪里在我的代码中设置 ActiveDirectoryServiceSettings.AzureChina 。请建议

<PackageReference Include="Azure.Identity" Version="1.5.0" />
<PackageReference Include="Azure.Security.KeyVault.Certificates" Version="4.2.0" />
<PackageReference Include="Azure.Security.KeyVault.Keys" Version="4.2.0" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.2.0" />

I use this code for Azure KeyVault Service and it works well with a regular Azure

ClientSecretCredential clientCredential = new(options.KeyVaultTenantId, options.KeyVaultClientId, options.KeyVaultClientSecret);
KeyVaultCertificateWithPolicy rootCertificate = new CertificateClient(vaultUri, _clientCredential).GetCertificate(_rootCertificateId).Value;

however I need to connect to Azure China. The code fails with message:

AADSTS90002: Tenant 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' not found.
Check to make sure you have the correct tenant ID and are signing into the correct cloud.
Check with your subscription administrator, this may happen if there
are no active subscriptions for the tenant

I found this but I don't know where to set ActiveDirectoryServiceSettings.AzureChina in my code. Please suggest

<PackageReference Include="Azure.Identity" Version="1.5.0" />
<PackageReference Include="Azure.Security.KeyVault.Certificates" Version="4.2.0" />
<PackageReference Include="Azure.Security.KeyVault.Keys" Version="4.2.0" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.2.0" />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多像笑话 2025-01-27 18:59:13

您需要使用 clients eptercretcredential(字符串,字符串,字符串,client并设置pertiateHost clientsecretcredentialOptions

像:

var clientSecretCredentialOptions = new ClientSecretCredentialOptions()
{
    AuthorityHost =  AzureAuthorityHosts.AzureChina
};

ClientSecretCredential clientCredential = new(options.KeyVaultTenantId, options.KeyVaultClientId, options.KeyVaultClientSecret, clientSecretCredentialOptions);
KeyVaultCertificateWithPolicy rootCertificate = new CertificateClient(vaultUri, _clientCredential).GetCertificate(_rootCertificateId).Value;

You would need to use ClientSecretCredential(String, String, String, ClientSecretCredentialOptions) constructor override and set the AuthorityHost to Azure China in ClientSecretCredentialOptions.

Something like:

var clientSecretCredentialOptions = new ClientSecretCredentialOptions()
{
    AuthorityHost =  AzureAuthorityHosts.AzureChina
};

ClientSecretCredential clientCredential = new(options.KeyVaultTenantId, options.KeyVaultClientId, options.KeyVaultClientSecret, clientSecretCredentialOptions);
KeyVaultCertificateWithPolicy rootCertificate = new CertificateClient(vaultUri, _clientCredential).GetCertificate(_rootCertificateId).Value;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文