msRestAzure.loginWithAppServiceMSI() .then(credentials => { computeClient = new computeManagementClient(credentials, subscriptionId); return computeClient.virtualMachines.listAll(); }) .then(vms => { done(context, 200, {vms: vms}); }) .catch(err => { doneWithError(context, err); });
function getKeyVaultCredentials(){ return msRestAzure.loginWithAppServiceMSI({resource: "https://vault.azure.net"}); }
// The ms-rest-azure library allows us to login with MSI by providing the resource name. In this case the resource is Key Vault. // For public regions the resource name is Key Vault msRestAzure.loginWithAppServiceMSI({resource: 'https://vault.azure.net'}).then( (credentials) => { const keyVaultClient = new KeyVault.KeyVaultClient(credentials); var vaultUri = "https://" + "<YourVaultName>" + ".vault.azure.net/"; // We're setting the Secret value here and retrieving the secret value keyVaultClient.setSecret(vaultUri, 'my-secret', 'test-secret-value', {}) .then( (kvSecretBundle, httpReq, httpResponse) => { console.log("Secret id: '" + kvSecretBundle.id + "'."); return keyVaultClient.getSecret(kvSecretBundle.id, {}); }) .then( (bundle) => { console.log("Successfully retrieved 'test-secret'"); console.log(bundle); }) .catch( (err) => { console.log(err); }); // Below code demonstrates how to retrieve a secret value // keyVaultClient.getSecret(vaultUri, "AppSecret", "").then(function(response){ // console.log(response); // }) });
// return the storage credentials function getStorageCredentials(){ return msRestAzure.loginWithAppServiceMSI({resource: 'https://storage.azure.com/'}); }