无法通过 Azure KeyVault 进行身份验证时,如何确定 "first party service" 是什么?

How can I identify what the "first party service" is when failing to authenticate to Azure KeyVault?

尽管进行了多个小时的故障排除,但我无法Visual Studio 对 Azure KeyVault 进行身份验证。无论我尝试什么,我都会收到以下无用的错误:

Service request failed. Status: 403 (Forbidden)

Content: {"error":{"code":"Forbidden","message":"Access denied to first party service.\r\nCaller: name=from-infra;tid=GUID_REDACTED;appid=GUID_REDACTED;iss=https://sts.windows.net/GUID_REDACTED/\r\nVault: VAULT_NAME;location=westus","innererror":{"code":"AccessDenied"}}}

这里有什么东西(可能是经过编辑的 GUID 值之一)我可以用来确定它有问题的“第一方服务”是什么吗?

我在“Azure 服务身份验证”部分使用我的 MSDN 帐户登录。 KeyVault 存在于该 MSDN 帐户中。该 KeyVault 中还有针对我的 MSDN 帐户和我的应用服务的主体 ID 的访问策略。在尝试进行身份验证时,这些似乎被完全忽略了。

这是我一直在尝试使用的基本代码。

            var credential = new VisualStudioCredential(new VisualStudioCredentialOptions { TenantId = "GUID from tid in above error" });

            // Create a secret client using the DefaultAzureCredential
            var client = new SecretClient(new Uri("https://MY_VAULT.vault.azure.net/"), new DefaultAzureCredential());

            var secret = client.GetSecret("MySecretId");

我已经尝试了多个版本的 VisualStudioCredential 和 DefaultAzureCredential。无论我做什么,我都无法摆脱这个“拒绝第一方服务访问”错误,所以我认为下一步是找出“第一方服务”是什么,因为它似乎不是我的 MSDN帐户或我的应用服务。

租户 f8cdef31-a31e-4b4a-93e4-5f571e91255a 是一个特殊租户,其中定义了 Microsoft 第一方应用程序。某些 ARM 和计算方案使用来自此租户的令牌访问 Key Vault,但通常 Key Vault 拒绝来自此租户的令牌并且它不可供客户使用。

您应该使用的租户是您在 Azure 门户中查看“Azure Active Directory”部分时显示在“租户 ID”下的租户。个人账户,如outlook.com账户,如果不指定自己的租户ID,可以获得第一方租户发放的代币。组织帐户根据与租户关联的经过验证的域从其主租户获取令牌,因此他们通常不需要明确指定租户 ID。