|defaultAzureCredential.js||Tries several authentications. The simplest way to use @azure/identity|
|clientSecretCredential.js||Authenticates with a client and a client's secret.|
|environmentCredential.js||Authenticates with a client and a client's secret sent through environment variables.|
The samples are compatible with Node.js >= 8.0.0.
To create an AAD application:
- Follow Documentation to register a new application in the Azure Active Directory (in the Azure portal).
- Note down the
- In the "Certificates & Secrets" tab, create a secret and note that down.
To allow your registered application to access your Key Vault
- In the Azure portal, go to your Azure Key Vault.
- In the left-side-navbar of your Azure Key Vault in the Azure portal, go to the
Access Policiessection, then click the
+ Add Access Policybutton.
- In the
Add access policypage, select all the permissions for Keys, Secrets and Certificates.
- For the
Select principalfield, click on the
None selected. A panel will appear at the right of the window. Search for your Azure Active Directory application, click the application on the search results, then click "Select" at the bottom.
- Once your application is selected, click the "Add" button.
- Click the
Savebutton at the top of the Access Policies section of your Key Vault.
- For more information on securing your Key Vault: Learn more
Adapting the samples to run in the browser may require some additional consideration. For details, please see the package README.
To run the samples using the published version of the package:
- Install the dependencies using
Edit the file
sample.env, adding the correct credentials to access the Azure service and run the samples. Then rename the file from
.env. The sample programs will read this file automatically.
Run whichever samples you like (note that some samples may require additional setup, see the table above):
Alternatively, run a single sample with the correct environment variables set (step 2 is not required if you do this), for example (cross-platform):
npx cross-env KEYVAULT_NAME="<key vault name>" AZURE_TENANT_ID="<AAD tenant id>" AZURE_CLIENT_ID="<AAD client id>" AZURE_CLIENT_SECRET="<AAD client secret>" node environmentCredential.js
Take a look at our API Documentation for more information about the APIs that are available in the clients.