在ms-rest-azure中,当我尝试获取身份验证令牌时,如何指定资源?

时间:2018-02-06 23:14:02

标签: node.js azure npm azure-keyvault azure-cli

所以我正在尝试对keyvault进行身份验证:

import * as msRestAzure from 'ms-rest-azure';
msRestAzure.loginWithServicePrincipalSecret(clientID, clientKey, domainID);

如何将资源指定为“https://vault.azure.net”?

1 个答案:

答案 0 :(得分:0)

您可以使用msRestAzure.loginWithAppServiceMSImsRestAzure.loginWithAppServiceMSI({resource: 'https://vault.azure.net'});

您可以查看link

function getKeyVaultCredentials(){
    return msRestAzure.loginWithAppServiceMSI({resource: 'https://vault.azure.net'});
}

function getKeyVaultSecret(credentials) {
    let keyVaultClient = new KeyVault.KeyVaultClient(credentials);
    return keyVaultClient.getSecret(KEY_VAULT_URI, 'secret', "");
}

getKeyVaultCredentials().then(
    getKeyVaultSecret
).then(function (secret){
    console.log(`Your secret value is: ${secret.value}.`);
}).catch(function (err) {
    throw (err);
});