> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cdp.coinbase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TokenProvider

> Provides authentication tokens for CDP API requests.

Package: [`com.coinbase.cdp.auth`](/sdks/cdp-sdks-v2/java/com/coinbase/cdp/auth/index)

```java theme={null}
public interface TokenProvider
```

Provides authentication tokens for CDP API requests.

This interface defines the contract for supplying bearer tokens and optional wallet auth tokens to CDP clients. It allows for flexible token provisioning from various sources, including internal token generators, external authentication services, or custom token management systems.

Implementations must provide:

* A bearer token for the `Authorization` header
* An optional wallet auth token for the `X-Wallet-Auth` header

Example implementation for a custom token source:

```

 public class ExternalTokenProvider implements TokenProvider {
     private final ExternalAuthService authService;

     public ExternalTokenProvider(ExternalAuthService authService) {
         this.authService = authService;
     }

     @Override
     public String bearerToken() {
         return authService.getBearerToken();
     }

     @Override
     public Optional<String> walletAuthToken() {
         return authService.getWalletAuthToken();
     }
 }

 // Usage with CDP clients
 TokenProvider tokens = new ExternalTokenProvider(authService);
 CdpClient client = CdpClient.builder()
     .tokenProvider(tokens)
     .build();
 EvmClient evmClient = client.evm();
 PoliciesClient policiesClient = client.policies();
 
```

The SDK provides a default implementation via [`CdpTokenResponse`](/sdks/cdp-sdks-v2/java/com/coinbase/cdp/auth/CdpTokenResponse "class in com.coinbase.cdp.auth") that is returned by [`CdpTokenGenerator`](/sdks/cdp-sdks-v2/java/com/coinbase/cdp/auth/CdpTokenGenerator "class in com.coinbase.cdp.auth").

## Method Details

### `bearerToken`

```java theme={null}
String bearerToken()
```

Returns the bearer token for the `Authorization` header.

This token is required for all CDP API requests and authenticates the client application.

**Returns:**

`String` - the bearer token (must not be null or blank)

### `walletAuthToken`

```java theme={null}
Optional<String> walletAuthToken()
```

Returns the optional wallet auth token for the `X-Wallet-Auth` header.

This token is required for write operations (POST, PUT, DELETE) on account endpoints. It includes a hash of the request body and additional request metadata for enhanced security.

**Returns:**

`Optional<String>` - an Optional containing the wallet auth token, or empty if not available
