Skip navigation

Authentication sample for Azure Key Vault using the Azure Node SDK

Last updated: 16/05/2018
Edit on GitHub

This sample repo demonstrates how to connect and authenticate to an Azure Key Vault vault. To do so, it first uses the Key Vault Management Client to create a vault. The Key Vault client is then used to authenticate to the vault and set/retrieve a sample secret.

How to run this sample

  1. If you don't already have it, get node.js.

  2. Clone the repo.

   git clone key-vault
  1. Install the dependencies.
   cd key-vault
   npm install
  1. Create an Azure service principals, using one of the following:

    This service principal is to run the sample on your azure account.

  2. Set the following environment variables using the information from the service principal that you created.

   export AZURE_SUBSCRIPTION_ID={your subscription id}
   export AZURE_CLIENT_ID={your client id}
   export AZURE_CLIENT_SECRET={your client secret}
   export AZURE_TENANT_ID={your tenant id as a GUID}
   export AZURE_CLIENT_OID={Object id of the service principal}

On Windows, use set instead of export.

  1. Run the sample.

    node authentication_sample.js

References and further reading