【发布时间】:2019-12-26 15:50:12
【问题描述】:
目前我在启动期间使用 Azure KeyVault 来加载一些配置,如下所示:
configBuilder
.AddAzureKeyVault(keyVaultConfigSection.Vault, GetKeyVaultClient(clientConfigSection, keyVaultConfigSection), new DefaultKeyVaultSecretManager())
.AddEnvironmentVariables();
private static KeyVaultClient GetKeyVaultClient(ClientConfigSection clientConfigSection, KeyVaultConfigSection keyVaultConfigSection)
{
HttpClient httpClient = null;
//proxy
if (!CustomEnvironment.NotProductionEnvironment())
{
var handler = new HttpClientHandler()
{
Proxy = new WebProxy(keyVaultConfigSection.Proxy),
UseProxy = true
};
httpClient = new HttpClient(handler);
}
return new KeyVaultClient(async (authority, resource, scope) =>
{
var authContext = new AuthenticationContext(authority);
var clientCred = new ClientCredential(clientConfigSection.ClientId, clientConfigSection.ClientSecret);
var result = await authContext.AcquireTokenAsync(resource, clientCred);
if (result == null)
throw new InvalidOperationException("Failed to retrieve access token for Key Vault");
return result.AccessToken;
}, httpClient ?? new HttpClient()
);
}
当我不在生产环境中时,这可以正常工作。 但是在我们的生产环境中,keyvault 被阻止了,所以我们必须通过代理。
但在运行代码时出现此错误:Microsoft.Azure.KeyVault.Models.KeyVaultErrorException: 'Operation returned an invalid status code 'BadRequest''
以前有没有人这样做过并且可以指出正确的方向?
【问题讨论】:
标签: c# azure asp.net-core azure-keyvault