docs
0
# Azure Developer CLI Authentication
1
2
Authenticates using Azure Developer CLI (azd) cached credentials from development environments, ideal for local development scenarios.
3
4
## Capabilities
5
6
### Azure Developer CLI Credential
7
8
Authenticates using cached credentials from Azure Developer CLI.
9
10
```java { .api }
11
/**
12
* Azure Developer CLI credential for development environments
13
*/
14
class AzureDeveloperCliCredential implements TokenCredential {
15
Mono<AccessToken> getToken(TokenRequestContext request);
16
AccessToken getTokenSync(TokenRequestContext request);
17
}
18
19
class AzureDeveloperCliCredentialBuilder extends CredentialBuilderBase<AzureDeveloperCliCredentialBuilder> {
20
AzureDeveloperCliCredentialBuilder tenantId(String tenantId);
21
AzureDeveloperCliCredentialBuilder processTimeout(Duration processTimeout);
22
AzureDeveloperCliCredentialBuilder additionallyAllowedTenants(String... additionallyAllowedTenants);
23
AzureDeveloperCliCredentialBuilder additionallyAllowedTenants(List<String> additionallyAllowedTenants);
24
AzureDeveloperCliCredential build();
25
}
26
```
27
28
**Usage Examples:**
29
30
```java
31
import com.azure.identity.AzureDeveloperCliCredential;
32
import com.azure.identity.AzureDeveloperCliCredentialBuilder;
33
import java.time.Duration;
34
35
// Basic usage - uses default settings
36
TokenCredential credential = new AzureDeveloperCliCredentialBuilder()
37
.build();
38
39
// With specific tenant
40
TokenCredential tenantCredential = new AzureDeveloperCliCredentialBuilder()
41
.tenantId("your-tenant-id")
42
.build();
43
44
// With custom process timeout
45
TokenCredential timeoutCredential = new AzureDeveloperCliCredentialBuilder()
46
.processTimeout(Duration.ofSeconds(30))
47
.build();
48
49
// Use with Azure SDK clients
50
ResourceManagementClient client = ResourceManagementClient.builder()
51
.credential(credential)
52
.subscriptionId("your-subscription-id")
53
.buildClient();
54
```
55
56
## Prerequisites
57
58
**Azure Developer CLI Installation:**
59
1. Install Azure Developer CLI: https://docs.microsoft.com/azure/developer/azure-developer-cli/install-azd
60
2. Sign in using: `azd auth login`
61
3. Verify authentication: `azd auth login --check-status`
62
63
**Supported Authentication Methods:**
64
- Interactive browser login
65
- Device code authentication
66
- Service principal (when configured in azd)
67
68
## Configuration Options
69
70
```java
71
// Multi-tenant support
72
TokenCredential credential = new AzureDeveloperCliCredentialBuilder()
73
.tenantId("primary-tenant-id")
74
.additionallyAllowedTenants("tenant1", "tenant2", "tenant3")
75
.processTimeout(Duration.ofSeconds(45))
76
.build();
77
```
78
79
## Process Timeout
80
81
The `processTimeout` setting controls how long to wait for the `azd` command to complete:
82
83
```java
84
// Short timeout for fast environments
85
TokenCredential fastCredential = new AzureDeveloperCliCredentialBuilder()
86
.processTimeout(Duration.ofSeconds(10))
87
.build();
88
89
// Longer timeout for slower environments
90
TokenCredential slowCredential = new AzureDeveloperCliCredentialBuilder()
91
.processTimeout(Duration.ofMinutes(2))
92
.build();
93
```
94
95
## Development Workflow
96
97
1. **Install and authenticate Azure Developer CLI:**
98
```bash
99
# Install azd
100
# Sign in interactively
101
azd auth login
102
103
# Or sign in with device code
104
azd auth login --use-device-code
105
```
106
107
2. **Use in your Java application:**
108
```java
109
TokenCredential credential = new AzureDeveloperCliCredentialBuilder().build();
110
111
// Use with any Azure SDK client
112
KeyVaultSecret secret = new SecretClientBuilder()
113
.vaultUrl("https://myvault.vault.azure.net/")
114
.credential(credential)
115
.buildClient()
116
.getSecret("mysecret");
117
```
118
119
## Exception Handling
120
121
Throws `CredentialUnavailableException` when:
122
- Azure Developer CLI is not installed
123
- User is not signed in (`azd auth login` not run)
124
- Process timeout is exceeded
125
- Command execution fails
126
127
## Troubleshooting
128
129
**Common Issues:**
130
- **"azd not found"**: Ensure Azure Developer CLI is installed and in PATH
131
- **"Not signed in"**: Run `azd auth login` to authenticate
132
- **Timeout errors**: Increase `processTimeout` duration
133
- **Permission errors**: Ensure azd has necessary permissions for token cache access