public async Task <string> GetPasswordAsync(string dpapiFilePath, System.Security.Cryptography.DataProtectionScope scope, Config.KeyVaultSecret secretsTuple) { if (secretsTuple == null) { if (string.IsNullOrWhiteSpace(dpapiFilePath)) { return(null); } if (!File.Exists(dpapiFilePath)) { throw new BadConfigException("Protected file missing", dpapiFilePath); } return(DPAPIHelper.ReadDataFromFile(dpapiFilePath, scope)); } if (string.IsNullOrWhiteSpace(secretsTuple.ApplicationIdEnvironmentVariableName)) { throw new BadConfigException("Application ID", "Empty Application ID variable name"); } if (string.IsNullOrWhiteSpace(secretsTuple.ApplicationSecretEnvironmentVariableName)) { throw new BadConfigException("Application Secret", "Empty Application Secret variable name"); } clientId = GetRequiredEnvironmentVariable(secretsTuple.ApplicationIdEnvironmentVariableName); clientSecret = GetRequiredEnvironmentVariable(secretsTuple.ApplicationSecretEnvironmentVariableName); var kv = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(GetToken)); var result = await kv.GetSecretAsync(secretsTuple.KeyVaultPath); return(result.Value); }
public string GetPassword(string dpapiFilePath, System.Security.Cryptography.DataProtectionScope scope, Config.KeyVaultSecret secretsTuple) { var task = GetPasswordAsync(dpapiFilePath, scope, secretsTuple); task.Wait(); if (task.IsFaulted) { throw task.Exception; } return(task.Result); }