Giter Site home page Giter Site logo

Error: credentials must be one of: ApplicationTokenCredentials, UserTokenCredentials, DeviceTokenCredentials, MSITokenCredentials about azure-sdk-for-js-keyvault-secret-get-set-managedid HOT 2 CLOSED

azure-samples avatar azure-samples commented on July 19, 2024
Error: credentials must be one of: ApplicationTokenCredentials, UserTokenCredentials, DeviceTokenCredentials, MSITokenCredentials

from azure-sdk-for-js-keyvault-secret-get-set-managedid.

Comments (2)

workfigure avatar workfigure commented on July 19, 2024

I found out temporary solution.
The problem is that
at line 54-68 of file /node_modules/azure-keyvault/node_modules/ms-rest-azure/lib/credentials/keyVaultCredentials.js, there is type comparison and it is the one causing the error. The object I am getting from the call msRestAzure.loginWithAppServiceMSI is MSIAppServiceTokenCredentials and I created this object by require('ms-rest-azure') but the object the azure-keyvault is comparing using the instance it loads by require('ms-rest-azure'). So the instance I created is not the same type of the azure-keyvault created even-if the node module is the same copy.

Here is the temporary solution to get key/secret from key vault.
First expose the msRestAzure from the azure-keyvault node module. To do that update the node_modules/azure-keyvault/lib/keyVault.js file with this one line code.
module.exports.msRestAzure = msRestAzure;

Then the method look like this:

const KeyVault = require('azure-keyvault');
var getKeyValue = async (secretName, secretVersion)=>{
// The ms-rest-azure library allows us to login with MSI by providing the resource name. In this case the resource is Key Vault.
return KeyVault.msRestAzure.loginWithAppServiceMSI({resource: 'https://vault.azure.net'})
.then((credentials) => {
var vaultUri = "https://.vault.azure.net/";
const client = new KeyVault.KeyVaultClient(credentials);
return client.getSecret(vaultUri, secretName, secretVersion)
.then((result) => {
return result.value;
})
.catch((err)=>{
console.log(err);
return err;
});
})
.catch((err)=>{
console.log(err);
return err;
});
};

from azure-sdk-for-js-keyvault-secret-get-set-managedid.

jongio avatar jongio commented on July 19, 2024

This should be resolved in latest update. Please reopen if you are able to repro. Thank you

from azure-sdk-for-js-keyvault-secret-get-set-managedid.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.