forked from theankeong/jmc-mining-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKV.js
34 lines (27 loc) · 1.22 KB
/
KV.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
async function f_getsecrets() {
const KeyVault = require('azure-keyvault');
const { AuthenticationContext } = require('adal-node')
const clientId = process.env.CLIENT_ID;
const clientSecret = process.env.CLIENT_SECRET;
const vaultUrl = process.env.VAULT_URL ;
const vaultName = process.env.VAULT_NAME ;
const vaultKey = process.env.VAULT_KEY ;
var secretAuthenticator = function (challenge, callback) {
var context = new AuthenticationContext(challenge.authorization);
return context.acquireTokenWithClientCredentials(
challenge.resource,
clientId,
clientSecret,
function (err, tokenResponse) {
if (err) throw err;
var authorizationValue = tokenResponse.tokenType + ' ' + tokenResponse.accessToken;
return callback(null, authorizationValue);
});
};
var credentials = new KeyVault.KeyVaultCredentials(secretAuthenticator);
var client = new KeyVault.KeyVaultClient(credentials);
var result = await client.getSecret(vaultUrl, vaultName, vaultKey);
return result.value.toString();
//console.log(result.value);
}
module.exports.f_getsecrets = f_getsecrets;