托管身份 - 如何在本地调试

Managed Identity - how to debug locally

我正在使用以下代码在我的 Web 应用程序上测试系统托管标识,当我在 Azure 中部署时它工作正常,但是有没有办法在本地进行测试(无需向我的 Azure 帐户授予该资源的权限?) ?

AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();

KeyVaultClient keyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
var secret = await keyVaultClient.GetSecretAsync("https://EASDemo.vault.azure.net/secrets/test")
                .ConfigureAwait(false);
return new string[] { secret.Value };

记录本地测试选项(VS、CLI)here

Authenticating with Visual Studio

To authenticate by using Visual Studio:

  1. Sign in to Visual Studio and use Tools > Options to open Options.
  2. Select Azure Service Authentication, choose an account for local development, and select OK.

If you run into problems using Visual Studio, such as errors that involve the token provider file, carefully review the preceding steps.

You may need to reauthenticate your developer token. To do so, select Tools > Options, and then select Azure Service Authentication. Look for a Re-authenticate link under the selected account. Select it to authenticate.

如果您不想使用您的开发者身份,您也可以使用证书或密钥(但不推荐,因为它可能会被错误地签入源存储库)。这些选项记录在案 here.