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

In ms-rest-azure, when I try to get authentication token, how do I specify resource?

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

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

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

您可以使用 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);
});