You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Quickstart: Azure Key Vault secret client library for JavaScript
15
15
16
16
Get started with the Azure Key Vault secret client library for JavaScript. [Azure Key Vault](../general/overview.md) is a cloud service that provides a secure store for secrets. You can securely store keys, passwords, certificates, and other secrets. Azure key vaults may be created and managed through the Azure portal. In this quickstart, you learn how to create, retrieve, and delete secrets from an Azure key vault using the JavaScript client library
17
17
@@ -39,7 +39,7 @@ This quickstart assumes you are running [Azure CLI](/cli/azure/install-azure-cli
39
39
40
40
1. Run the `login` command.
41
41
42
-
```azurecli-interactive
42
+
```azurecli
43
43
az login
44
44
```
45
45
@@ -67,62 +67,90 @@ Create a Node.js application that uses your key vault.
67
67
68
68
## Install Key Vault packages
69
69
70
-
1. Using the terminal, install the Azure Key Vault secrets library, [@azure/keyvault-secrets](https://www.npmjs.com/package/@azure/keyvault-secrets) for Node.js.
70
+
1. Using the terminal, install the Azure Key Vault secrets client library, [@azure/keyvault-secrets](https://www.npmjs.com/package/@azure/keyvault-secrets) for Node.js.
71
71
72
72
```terminal
73
73
npm install @azure/keyvault-secrets
74
74
```
75
75
76
-
1. Install the Azure Identity library, [@azure/identity](https://www.npmjs.com/package/@azure/identity) package to authenticate to a Key Vault.
76
+
1. Install the Azure Identity client library, [@azure/identity](https://www.npmjs.com/package/@azure/identity) package to authenticate to a Key Vault.
77
77
78
78
```terminal
79
79
npm install @azure/identity
80
80
```
81
81
82
82
## Grant access to your key vault
83
83
84
-
Create an access policy for your key vault that grants secret permissions to your user account with the [az keyvault set-policy](/cli/azure/keyvault#az-keyvault-set-policy) command.
84
+
Create a vault access policy for your key vault that grants secret permissions to your user account with the [az keyvault set-policy](/cli/azure/keyvault#az-keyvault-set-policy) command.
85
85
86
86
```azurecli
87
-
az keyvault set-policy --name <your-key-vault-name> --upn [email protected] --secret-permissions delete get list set purge
87
+
az keyvault set-policy --name <your-key-vault-name> --upn [email protected] --secret-permissions delete get list set purge update
88
88
```
89
89
90
90
## Set environment variables
91
91
92
92
This application is using key vault name as an environment variable called `KEY_VAULT_NAME`.
93
93
94
-
Windows
94
+
### [Windows](#tab/windows)
95
+
95
96
```cmd
96
97
set KEY_VAULT_NAME=<your-key-vault-name>
97
98
````
99
+
100
+
### [PowerShell](#tab/powershell)
101
+
98
102
Windows PowerShell
99
103
```powershell
100
104
$Env:KEY_VAULT_NAME="<your-key-vault-name>"
101
105
```
102
106
103
-
macOS or Linux
107
+
### [macOS or Linux](#tab/linux)
108
+
104
109
```cmd
105
110
export KEY_VAULT_NAME=<your-key-vault-name>
106
111
```
112
+
---
113
+
114
+
115
+
## Authenticate and create a client
116
+
117
+
Application requests to most Azure services must be authorized. Using the [DefaultAzureCredential](/javascript/api/@azure/identity/#@azure-identity-getdefaultazurecredential) method provided by the [Azure Identity client library](/javascript/api/@azure/identity) is the recommended approach for implementing passwordless connections to Azure services in your code. `DefaultAzureCredential` supports multiple authentication methods and determines which method should be used at runtime. This approach enables your app to use different authentication methods in different environments (local vs. production) without implementing environment-specific code.
118
+
119
+
In this quickstart, `DefaultAzureCredential` authenticates to key vault using the credentials of the local development user logged into the Azure CLI. When the application is deployed to Azure, the same `DefaultAzureCredential` code can automatically discover and use a managed identity that is assigned to an App Service, Virtual Machine, or other services. For more information, see [Managed Identity Overview](/azure/active-directory/managed-identities-azure-resources/overview).
120
+
121
+
In this code, the name of your key vault is used to create the key vault URI, in the format `https://<your-key-vault-name>.vault.azure.net`. For more information about authenticating to key vault, see [Developer's Guide](/azure/key-vault/general/developers-guide#authenticate-to-key-vault-in-code).
107
122
108
123
## Code example
109
124
110
125
The code samples below will show you how to create a client, set a secret, retrieve a secret, and delete a secret.
111
126
127
+
This code uses the following [Key Vault Secret classes and methods](/javascript/api/overview/azure/keyvault-secretss-readme):
0 commit comments