英文:
how to authenticate azure key vault using client id and secret?
问题
我有一个 Azure 密钥保管库,并尝试从该保管库中获取密钥并在 Node.js 控制台中打印出来。这是我从文档中获得的代码:
const { DefaultAzureCredential} = require("@azure/identity");
const { SecretClient } = require("@azure/keyvault-secrets");
const credential = new DefaultAzureCredential();
// Build the URL to reach your key vault
const vaultName = "web-designer";
const url = `https://${vaultName}.vault.azure.net`;
// Lastly, create our secrets client and connect to the service
const client = new SecretClient(url, credential);
const secretName = "web-designer-secret";
client.getSecret(secretName).then((res)=>{
console.log(res);
}).catch((err)=>{
console.log("error",err);
})
在这里,他们使用 DefaultAzureCredential 来验证帐户。但我想要使用客户端 ID 和客户端密钥来验证我的密钥保管库,而不是使用 DefaultAzureCredential。如何在不使用 DefaultAzureCredential 的情况下执行此操作?
我尝试使用 ManagedIdentityCredential,但不起作用。
英文:
I have a azure key vault and i am trying to get the secret from that vault and print it in console in node js. This is the code i got from documentation,
const { DefaultAzureCredential} = require("@azure/identity");
const { SecretClient } = require("@azure/keyvault-secrets");
const credential = new DefaultAzureCredential();
// Build the URL to reach your key vault
const vaultName = "web-designer";
const url = `https://${vaultName}.vault.azure.net`;
// Lastly, create our secrets client and connect to the service
const client = new SecretClient(url, credential);
const secretName = "web-designer-secret";
client.getSecret(secretName).then((res)=>{
console.log(res);
}).catch((err)=>{
console.log("error",err);
})
Here they are using DefaultAzurecredential to validate account. But instead of that i want to use client id and client secret to validate my key vault. How to do this without DefaultAzureCredential?
I tried ManagedIdentityCredential but not working.
答案1
得分: 1
以下是已翻译的内容:
在我这边重新生成后,我成功使用以下代码实现了使用 ClientSecretCredential
进行身份验证。
const { ClientSecretCredential } = require("@azure/identity");
const { SecretClient } = require("@azure/keyvault-secrets");
const credential = new ClientSecretCredential("<TENANTID>","<CLIENTID>","<CLIENTSECRET>");
const vaultName = "<VAULTNAME>";
const url = `https://${vaultName}.vault.azure.net`;
const client = new SecretClient(url, credential);
const secretName = "<SECRETNAME>";
client.getSecret(secretName).then((res)=>{
console.log(res);
}).catch((err)=>{
console.log("error",err);
})
RESULTS:
英文:
After reproducing from my end, I could able to achieve Authentication using ClientSecretCredential
following the below code.
const { ClientSecretCredential } = require("@azure/identity");
const { SecretClient } = require("@azure/keyvault-secrets");
const credential = new ClientSecretCredential("<TENANTID>","<CLIENTID>","<CLIENTSECRET>");
const vaultName = "<VAULTNAME>";
const url = `https://${vaultName}.vault.azure.net`;
const client = new SecretClient(url, credential);
const secretName = "<SECRETNAME>";
client.getSecret(secretName).then((res)=>{
console.log(res);
}).catch((err)=>{
console.log("error",err);
})
RESULTS:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论