目前,我在启动期间使用 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''
以前有人这样做过并且可以指出我正确的方向吗?
慕的地10843
相关分类