> ## 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.

# CdpTokenGenerator

> Unified token generator for CDP authentication.

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

```java theme={null}
public class CdpTokenGenerator extends Object
```

Unified token generator for CDP authentication.

Generates bearer tokens and optionally wallet auth tokens in a single call. This class composes the existing [`JwtGenerator`](/sdks/cdp-sdks-v2/java/com/coinbase/cdp/auth/JwtGenerator "class in com.coinbase.cdp.auth") and [`WalletJwtGenerator`](/sdks/cdp-sdks-v2/java/com/coinbase/cdp/auth/WalletJwtGenerator "class in com.coinbase.cdp.auth") to provide a simplified, unified API.

Example usage:

```

 // With wallet secret for write operations
 CdpTokenGenerator generator = new CdpTokenGenerator(
     "api-key-id", "api-key-secret", Optional.of("wallet-secret"));

 CdpTokenRequest request = CdpTokenRequest.builder()
     .requestMethod("POST")
     .requestPath("/v2/evm/accounts")
     .includeWalletAuthToken(true)
     .requestBody(Map.of("name", "my-account"))
     .build();

 CdpTokenResponse tokens = generator.generateTokens(request);
 // tokens.bearerToken() - for Authorization header
 // tokens.walletAuthToken() - for X-Wallet-Auth header
 
```

## Constructor Details

### `CdpTokenGenerator`

**Overload 1**

```java theme={null}
public CdpTokenGenerator(String apiKeyId, String apiKeySecret, Optional<String> walletSecret)
```

Creates a new token generator with default expiration.

**Parameters:**

`apiKeyId` (`String`) - the API key ID

`apiKeySecret` (`String`) - the API key secret (PEM EC key or base64 Ed25519 key)

`walletSecret` (`Optional<String>`) - optional wallet secret for wallet auth tokens

**Overload 2**

```java theme={null}
public CdpTokenGenerator(String apiKeyId, String apiKeySecret, Optional<String> walletSecret, long expiresIn)
```

Creates a new token generator with custom expiration.

**Parameters:**

`apiKeyId` (`String`) - the API key ID

`apiKeySecret` (`String`) - the API key secret (PEM EC key or base64 Ed25519 key)

`walletSecret` (`Optional<String>`) - optional wallet secret for wallet auth tokens

`expiresIn` (`long`) - JWT expiration time in seconds

## Method Details

### `generateTokens`

```java theme={null}
public CdpTokenResponse generateTokens(CdpTokenRequest request)
```

Generates authentication tokens based on the request configuration.

**Parameters:**

`request` ([CdpTokenRequest](/sdks/cdp-sdks-v2/java/com/coinbase/cdp/auth/CdpTokenRequest)) - the token request configuration

**Returns:**

[CdpTokenResponse](/sdks/cdp-sdks-v2/java/com/coinbase/cdp/auth/CdpTokenResponse) - the generated tokens

**Throws:**

`[WalletSecretException](/sdks/cdp-sdks-v2/java/com/coinbase/cdp/auth/exceptions/WalletSecretException "class in com.coinbase.cdp.auth.exceptions")` - if wallet auth is requested but no wallet secret is configured

### `generateBearerToken`

```java theme={null}
public String generateBearerToken(String method, String host, String path)
```

Generates only a bearer token (convenience method).

**Parameters:**

`method` (`String`) - the HTTP method

`host` (`String`) - the request host

`path` (`String`) - the request path

**Returns:**

`String` - the bearer token

### `hasWalletSecret`

```java theme={null}
public boolean hasWalletSecret()
```

Returns whether this generator has a wallet secret configured.

**Returns:**

`boolean` - true if wallet secret is available
