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

# CdpTokenResponse

> Response containing generated CDP authentication tokens.

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

```java theme={null}
public record CdpTokenResponse(String bearerToken, Optional<String> walletAuthToken) extends Record implements TokenProvider
```

Response containing generated CDP authentication tokens.

Always contains a bearer token. Optionally contains a wallet auth token if `includeWalletAuthToken` was set to true in the request.

This class implements [`TokenProvider`](/sdks/cdp-sdks-v2/java/com/coinbase/cdp/auth/TokenProvider "interface in com.coinbase.cdp.auth") and can be used wherever token providers are accepted, such as in CDP client factory methods.

Example usage:

```

 CdpTokenResponse response = generator.generateTokens(request);

 // Bearer token for Authorization header
 String bearerToken = response.bearerToken();

 // Wallet auth token for X-Wallet-Auth header (if requested)
 response.walletAuthToken().ifPresent(walletJwt -> {
     // Use wallet JWT
 });

 // Use as TokenProvider
 CdpClient client = CdpClient.builder()
     .tokenProvider(response)
     .build();
 EvmClient evmClient = client.evm();
 
```

## Constructor Details

### `CdpTokenResponse`

```java theme={null}
public CdpTokenResponse(String bearerToken, Optional<String> walletAuthToken)
```

Validates the token response.

**Throws:**

`[IllegalArgumentException](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/IllegalArgumentException.html "class or interface in java.lang")` - if validation fails

**Parameters:**

`bearerToken` - `String`

`walletAuthToken` - `Optional<String>`

## Method Details

### `bearerOnly`

```java theme={null}
public static CdpTokenResponse bearerOnly(String bearerToken)
```

Creates a response with only a bearer token.

**Parameters:**

`bearerToken` (`String`) - the bearer token

**Returns:**

[CdpTokenResponse](/sdks/cdp-sdks-v2/java/com/coinbase/cdp/auth/CdpTokenResponse) - the token response

### `withWalletAuth`

```java theme={null}
public static CdpTokenResponse withWalletAuth(String bearerToken, String walletAuthToken)
```

Creates a response with both bearer and wallet auth tokens.

**Parameters:**

`bearerToken` (`String`) - the bearer token

`walletAuthToken` (`String`) - the wallet auth token

**Returns:**

[CdpTokenResponse](/sdks/cdp-sdks-v2/java/com/coinbase/cdp/auth/CdpTokenResponse) - the token response

### `toString`

```java theme={null}
public final String toString()
```

Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.

**Specified by:**

`[toString](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Record.html#toString\(\) "class or interface in java.lang")` in class `[Record](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Record.html "class or interface in java.lang")`

**Returns:**

`String` - a string representation of this object

### `hashCode`

```java theme={null}
public final int hashCode()
```

Returns a hash code value for this object. The value is derived from the hash code of each of the record components.

**Specified by:**

`[hashCode](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Record.html#hashCode\(\) "class or interface in java.lang")` in class `[Record](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Record.html "class or interface in java.lang")`

**Returns:**

`int` - a hash code value for this object

### `equals`

```java theme={null}
public final boolean equals(Object o)
```

Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with [`Objects::equals(Object,Object)`](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Objects.html#equals\(java.lang.Object,java.lang.Object\) "class or interface in java.util").

**Specified by:**

`[equals](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Record.html#equals\(java.lang.Object\) "class or interface in java.lang")` in class `[Record](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Record.html "class or interface in java.lang")`

**Parameters:**

`o` (`Object`) - the object with which to compare

**Returns:**

`boolean` - `true` if this object is the same as the `o` argument; `false` otherwise.

### `bearerToken`

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

Returns the value of the `bearerToken` record component.

**Specified by:**

`[bearerToken](/sdks/cdp-sdks-v2/java/com/coinbase/cdp/auth/TokenProvider)` in interface `[TokenProvider](/sdks/cdp-sdks-v2/java/com/coinbase/cdp/auth/TokenProvider "interface in com.coinbase.cdp.auth")`

**Returns:**

`String` - the value of the `bearerToken` record component

### `walletAuthToken`

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

Returns the value of the `walletAuthToken` record component.

**Specified by:**

`[walletAuthToken](/sdks/cdp-sdks-v2/java/com/coinbase/cdp/auth/TokenProvider)` in interface `[TokenProvider](/sdks/cdp-sdks-v2/java/com/coinbase/cdp/auth/TokenProvider "interface in com.coinbase.cdp.auth")`

**Returns:**

`Optional<String>` - the value of the `walletAuthToken` record component
