Buscando segredos do keyVault do Azure em c #
Tenho o seguinte código, que recupera os segredos do KeyVaul
var kv = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(GetToken));
var sec = await kv.GetSecretAsync(ConfigurationManager.AppSettings["SomeURI"]);
secretValue = sec.Value ;
GetToken método:
async Task<string> GetToken(string authority, string resource, string scope)
{
var authContext = new AuthenticationContext(authority);
ClientCredential clientCred = new ClientCredential(ConfigurationManager.AppSettings["ClientId"],ConfigurationManager.AppSettings["ClientSecret"]);
AuthenticationResult result = await authContext.AcquireTokenAsync(resource, clientCred);
if (result == null)
throw new InvalidOperationException("Failed to obtain the token");
return result.AccessToken;
}
o método GetToken, estou buscando oClientId
eClientSecret
do Appconfig.
Sinto que não é seguro manter esses valores no Appconfig e usá-los. Existe uma maneira de remover do arquivo de configuração e buscar em qualquer outro lugar. Ou existe alguma boa solução possível para o meu problema.
Qualquer resposta é muito apreciada!
PS: Mine é um serviço do Windows desenvolvido em c #