Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Authenticate Java applications with Azure services using Microsoft Entra ID (Azure AD).
.claude/skills/azure-identity-java/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-10 | ✗→✓ | ▲ Improved | — | — |
| case-16 | ✗→✓ | ▲ Improved | — | — |
| case-05 | ✗→✓ | ▲ Improved | — | — |
| case-13 | ✗→✓ | ▲ Improved | — | — |
| case-03 | ✓→✓ | = Same ✓ | — | — |
Authenticate Java applications with Azure services using Microsoft Entra ID (Azure AD).
xml<dependency> <groupId>com.azure</groupId> <artifactId>azure-identity</artifactId> <version>1.15.0</version> </dependency>
| Credential | Use Case | |------------|----------| | DefaultAzureCredential | Recommended - Works in dev and production | | ManagedIdentityCredential | Azure-hosted apps (App Service, Functions, VMs) | | EnvironmentCredential | CI/CD pipelines with env vars | | ClientSecretCredential | Service principals with secret | | ClientCertificateCredential | Service principals with certificate | | AzureCliCredential | Local dev using az login | | InteractiveBrowserCredential | Interactive login flow | | DeviceCodeCredential | Headless device authentication |
The DefaultAzureCredential tries multiple authentication methods in order:
javaimport com.azure.identity.DefaultAzureCredential; import com.azure.identity.DefaultAzureCredentialBuilder; // Simple usage DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build(); // Use with any Azure client BlobServiceClient blobClient = new BlobServiceClientBuilder() .endpoint("https://<storage-account>.blob.core.windows.net") .credential(credential) .buildClient(); KeyClient keyClient = new KeyClientBuilder() .vaultUrl("https://<vault-name>.vault.azure.net") .credential(credential) .buildClient();
javaDefaultAzureCredential credential = new DefaultAzureCredentialBuilder() .managedIdentityClientId("<user-assigned-identity-client-id>") // For user-assigned MI .tenantId("<tenant-id>") // Limit to specific tenant .excludeEnvironmentCredential() // Skip env vars .excludeAzureCliCredential() // Skip Azure CLI .build();
For Azure-hosted applications (App Service, Functions, AKS, VMs).
javaimport com.azure.identity.ManagedIdentityCredential; import com.azure.identity.ManagedIdentityCredentialBuilder; // System-assigned managed identity ManagedIdentityCredential credential = new ManagedIdentityCredentialBuilder() .build(); // User-assigned managed identity (by client ID) ManagedIdentityCredential credential = new ManagedIdentityCredentialBuilder() .clientId("<user-assigned-client-id>") .build(); // User-assigned managed identity (by resource ID) ManagedIdentityCredential credential = new ManagedIdentityCredentialBuilder() .resourceId("/subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<name>") .build();
javaimport com.azure.identity.ClientSecretCredential; import com.azure.identity.ClientSecretCredentialBuilder; ClientSecretCredential credential = new ClientSecretCredentialBuilder() .tenantId("<tenant-id>") .clientId("<client-id>") .clientSecret("<client-secret>") .build();
javaimport com.azure.identity.ClientCertificateCredential; import com.azure.identity.ClientCertificateCredentialBuilder; // From PEM file ClientCertificateCredential credential = new ClientCertificateCredentialBuilder() .tenantId("<tenant-id>") .clientId("<client-id>") .pemCertificate("<path-to-cert.pem>") .build(); // From PFX file with password ClientCertificateCredential credential = new ClientCertificateCredentialBuilder() .tenantId("<tenant-id>") .clientId("<client-id>") .pfxCertificate("<path-to-cert.pfx>", "<pfx-password>") .build(); // Send certificate chain for SNI ClientCertificateCredential credential = new ClientCertificateCredentialBuilder() .tenantId("<tenant-id>") .clientId("<client-id>") .pemCertificate("<path-to-cert.pem>") .sendCertificateChain(true) .build();
Reads credentials from environment variables.
javaimport com.azure.identity.EnvironmentCredential; import com.azure.identity.EnvironmentCredentialBuilder; EnvironmentCredential credential = new EnvironmentCredentialBuilder().build();
For service principal with secret:
bashAZURE_TENANT_ID=<tenant-id> AZURE_CLIENT_ID=<client-id> AZURE_CLIENT_SECRET=<client-secret>
For service principal with certificate:
bashAZURE_TENANT_ID=<tenant-id> AZURE_CLIENT_ID=<client-id> AZURE_CLIENT_CERTIFICATE_PATH=/path/to/cert.pem AZURE_CLIENT_CERTIFICATE_PASSWORD=<optional-password>
For username/password:
bashAZURE_TENANT_ID=<tenant-id> AZURE_CLIENT_ID=<client-id> AZURE_USERNAME=<username> AZURE_PASSWORD=<password>
For local development using az login.
javaimport com.azure.identity.AzureCliCredential; import com.azure.identity.AzureCliCredentialBuilder; AzureCliCredential credential = new AzureCliCredentialBuilder() .tenantId("<tenant-id>") // Optional: specific tenant .build();
For desktop applications requiring user login.
javaimport com.azure.identity.InteractiveBrowserCredential; import com.azure.identity.InteractiveBrowserCredentialBuilder; InteractiveBrowserCredential credential = new InteractiveBrowserCredentialBuilder() .clientId("<client-id>") .redirectUrl("http://localhost:8080") // Must match app registration .build();
For headless devices (IoT, CLI tools).
javaimport com.azure.identity.DeviceCodeCredential; import com.azure.identity.DeviceCodeCredentialBuilder; DeviceCodeCredential credential = new DeviceCodeCredentialBuilder() .clientId("<client-id>") .challengeConsumer(challenge -> { // Display to user System.out.println(challenge.getMessage()); }) .build();
Create custom authentication chains.
javaimport com.azure.identity.ChainedTokenCredential; import com.azure.identity.ChainedTokenCredentialBuilder; ChainedTokenCredential credential = new ChainedTokenCredentialBuilder() .addFirst(new ManagedIdentityCredentialBuilder().build()) .addLast(new AzureCliCredentialBuilder().build()) .build();
For Azure Kubernetes Service with workload identity.
javaimport com.azure.identity.WorkloadIdentityCredential; import com.azure.identity.WorkloadIdentityCredentialBuilder; // Reads from AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_FEDERATED_TOKEN_FILE WorkloadIdentityCredential credential = new WorkloadIdentityCredentialBuilder().build(); // Or explicit configuration WorkloadIdentityCredential credential = new WorkloadIdentityCredentialBuilder() .tenantId("<tenant-id>") .clientId("<client-id>") .tokenFilePath("/var/run/secrets/azure/tokens/azure-identity-token") .build();
Enable persistent token caching for better performance.
java// Enable token caching (in-memory by default) DefaultAzureCredential credential = new DefaultAzureCredentialBuilder() .enableAccountIdentifierLogging() .build(); // With shared token cache (for multi-credential scenarios) SharedTokenCacheCredential credential = new SharedTokenCacheCredentialBuilder() .clientId("<client-id>") .build();
javaimport com.azure.identity.AzureAuthorityHosts; // Azure Government DefaultAzureCredential govCredential = new DefaultAzureCredentialBuilder() .authorityHost(AzureAuthorityHosts.AZURE_GOVERNMENT) .build(); // Azure China DefaultAzureCredential chinaCredential = new DefaultAzureCredentialBuilder() .authorityHost(AzureAuthorityHosts.AZURE_CHINA) .build();
javaimport com.azure.identity.CredentialUnavailableException; import com.azure.core.exception.ClientAuthenticationException; try { DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build(); AccessToken token = credential.getToken(new TokenRequestContext() .addScopes("https://management.azure.com/.default")); } catch (CredentialUnavailableException e) { // No credential could authenticate System.out.println("Authentication failed: " + e.getMessage()); } catch (ClientAuthenticationException e) { // Authentication error (wrong credentials, expired, etc.) System.out.println("Auth error: " + e.getMessage()); }
Enable authentication logging for debugging.
java// Via environment variable // AZURE_LOG_LEVEL=verbose // Or programmatically DefaultAzureCredential credential = new DefaultAzureCredentialBuilder() .enableAccountIdentifierLogging() // Log account info .build();
bash# DefaultAzureCredential configuration AZURE_TENANT_ID=<tenant-id> AZURE_CLIENT_ID=<client-id> AZURE_CLIENT_SECRET=<client-secret> # Managed Identity AZURE_CLIENT_ID=<user-assigned-mi-client-id> # Workload Identity (AKS) AZURE_FEDERATED_TOKEN_FILE=/var/run/secrets/azure/tokens/azure-identity-token # Logging AZURE_LOG_LEVEL=verbose # Authority host AZURE_AUTHORITY_HOST=https://login.microsoftonline.com/
az login before running your app| Environment | Recommended Credential | |-------------|----------------------| | Local Development | DefaultAzureCredential (uses Azure CLI) | | Azure App Service | DefaultAzureCredential (uses Managed Identity) | | Azure Functions | DefaultAzureCredential (uses Managed Identity) | | Azure Kubernetes Service | WorkloadIdentityCredential | | Azure VMs | DefaultAzureCredential (uses Managed Identity) | | CI/CD Pipeline | EnvironmentCredential | | Desktop App | InteractiveBrowserCredential | | CLI Tool | DeviceCodeCredential |
This skill is applicable to execute the workflow or actions described in the overview.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-11 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-12 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-10 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-04 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-03 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-21 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-09 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-06 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-18 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-01 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-16 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-14 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-23 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-05 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-15 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-17 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-02 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-22 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-20 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-13 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-07 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-08 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-19 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted. The headline lift of +17 percentage points is the difference between those two pass rates over the 23 comparable cases.
The per-case answers from this run were removed by the retention sweep, so the case table below shows the verdicts without the text either arm produced. The counts above were recorded at the time and are unaffected. Answers are now kept for 180 days.
Other measured skills in the registry, with their headline benchmark lift.