or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

advanced-authentication-flows.mdauthorization-code-authentication.mdazure-developer-cli-authentication.mdazure-pipelines-authentication.mdclient-assertion-authentication.mdconfiguration-and-utilities.mdcredential-chaining.mddefault-azure-credential.mddeveloper-tool-credentials.mdenvironment-credential.mdindex.mdinteractive-user-authentication.mdmanaged-identity-credential.mdservice-principal-authentication.mdshared-token-cache-authentication.mdusername-password-authentication.mdvisual-studio-code-authentication.md

environment-credential.mddocs/

0

# Environment Credential

1

2

Authenticates using environment variables for service principal credentials, supporting both client secret and client certificate authentication.

3

4

## Capabilities

5

6

### Environment Variable Authentication

7

8

Reads credential information from environment variables to authenticate service principals.

9

10

```java { .api }

11

/**

12

* Authenticates using environment variables for service principal credentials

13

*/

14

class EnvironmentCredential implements TokenCredential {

15

Mono<AccessToken> getToken(TokenRequestContext request);

16

AccessToken getTokenSync(TokenRequestContext request);

17

}

18

19

class EnvironmentCredentialBuilder extends CredentialBuilderBase<EnvironmentCredentialBuilder> {

20

EnvironmentCredentialBuilder authorityHost(String authorityHost);

21

EnvironmentCredentialBuilder executorService(ExecutorService executorService);

22

EnvironmentCredential build();

23

}

24

```

25

26

**Supported Environment Variables:**

27

28

**For Client Secret Authentication:**

29

- `AZURE_CLIENT_ID` - The application (client) ID

30

- `AZURE_CLIENT_SECRET` - The client secret

31

- `AZURE_TENANT_ID` - The tenant ID

32

- `AZURE_AUTHORITY_HOST` (optional) - The authority host URL

33

34

**For Client Certificate Authentication:**

35

- `AZURE_CLIENT_ID` - The application (client) ID

36

- `AZURE_CLIENT_CERTIFICATE_PATH` - Path to PEM or PFX certificate file

37

- `AZURE_CLIENT_CERTIFICATE_PASSWORD` - Certificate password (if required)

38

- `AZURE_TENANT_ID` - The tenant ID

39

- `AZURE_AUTHORITY_HOST` (optional) - The authority host URL

40

41

**Usage Examples:**

42

43

```java

44

import com.azure.identity.EnvironmentCredential;

45

import com.azure.identity.EnvironmentCredentialBuilder;

46

47

// Create credential using environment variables

48

TokenCredential credential = new EnvironmentCredentialBuilder()

49

.build();

50

51

// Use with Azure SDK clients

52

SecretClient client = new SecretClientBuilder()

53

.vaultUrl("https://myvault.vault.azure.net/")

54

.credential(credential)

55

.buildClient();

56

```

57

58

## Exception Handling

59

60

Throws `CredentialUnavailableException` when required environment variables are not set or invalid.