Authentication samples for Azure Key Vault using the Azure Java SDK

This sample repo contains sample code demonstrating common mechanisms for authenticating to an Azure Key Vault.

Samples in this repo

  • KeyVaultCertificateAuthenticator -- authenticates to an Azure Key Vault through a service principal with a self signed certificate. This takes in a pem file with the certificate and private key. This is the recommended way to authenticate to Key Vault.
  • KeyVaultADALAuthenticator -- authenticates to an Azure Key Vault by providing a callback to authenticate using ADAL.


  • Java 1.7+
  • An Azure Service Principal, through Azure CLI, PowerShell or Azure Portal.
  • A self signed certificate, uploaded to your service principal through Azure Portal or Powershell.

Running the samples

  1. If not installed, install Java.

  2. Clone the repository.

git clone
  1. Create an Azure service principal, using Azure CLI, PowerShell or Azure Portal. Note that if you wish to authenticate with the certificate authenticator the certificate should be saved locally.

  2. Use an authentication file to authenticate to the Azure management plane.

  3. Add these variables to pom.xml for a demo of certificate authentication. Note that CERTIFICATE_PASSWORD is optional depending on whether or not your .pem file requires a certificate.


For ADAL authentication, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET also must be set.

  1. Run mvn clean compile exec:java for a sample run through.

More information