# Class GdchCredentials (1.46.0)

1.46.0 (latest) 1.43.0 1.42.1 1.41.0 1.40.0 1.39.1 1.38.0 1.37.1 1.36.0 1.35.0 1.34.0 1.33.1 1.32.1 1.31.0 1.30.1 1.29.1-SNAPSHOT 1.28.0 1.27.0 1.26.0 1.25.0 1.24.1 1.20.0 1.19.0 1.18.0 1.7.0 1.6.1 1.4.0 1.3.0

    public class GdchCredentials extends GoogleCredentials

## Inheritance

[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> [Credentials](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.Credentials) \> [OAuth2Credentials](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials) \> [GoogleCredentials](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials) \> GdchCredentials

## Inherited Members

[Credentials.blockingGetToCallback(URI,RequestMetadataCallback)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.Credentials#com_google_auth_Credentials_blockingGetToCallback_java_net_URI_com_google_auth_RequestMetadataCallback_) [Credentials.getMetricsCredentialType()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.Credentials#com_google_auth_Credentials_getMetricsCredentialType__) [Credentials.getRequestMetadata()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.Credentials#com_google_auth_Credentials_getRequestMetadata__) [GoogleCredentials.create(AccessToken)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_create_com_google_auth_oauth2_AccessToken_) [GoogleCredentials.create(String,AccessToken)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_create_java_lang_String_com_google_auth_oauth2_AccessToken_) [GoogleCredentials.createDelegated(String)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_createDelegated_java_lang_String_) [GoogleCredentials.createScoped(String)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_createScoped_java_lang_String____) [GoogleCredentials.createScoped(Collection\<String\>)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_createScoped_java_util_Collection_java_lang_String__) [GoogleCredentials.createScoped(Collection\<String\>,Collection\<String\>)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_createScoped_java_util_Collection_java_lang_String__java_util_Collection_java_lang_String__) [GoogleCredentials.createScopedRequired()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_createScopedRequired__) [GoogleCredentials.createWithCustomRetryStrategy(boolean)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_createWithCustomRetryStrategy_boolean_) [GoogleCredentials.createWithQuotaProject(String)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_createWithQuotaProject_java_lang_String_) [GoogleCredentials.equals(Object)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_equals_java_lang_Object_) [GoogleCredentials.fromStream(InputStream)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_fromStream_java_io_InputStream_) [GoogleCredentials.fromStream(InputStream,HttpTransportFactory)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_fromStream_java_io_InputStream_com_google_auth_http_HttpTransportFactory_) [GoogleCredentials.getAdditionalHeaders()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_getAdditionalHeaders__) [GoogleCredentials.getApplicationDefault()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_getApplicationDefault__) [GoogleCredentials.getApplicationDefault(HttpTransportFactory)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_getApplicationDefault_com_google_auth_http_HttpTransportFactory_) [GoogleCredentials.getCredentialInfo()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_getCredentialInfo__) [GoogleCredentials.getProjectId()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_getProjectId__) [GoogleCredentials.getQuotaProjectId()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_getQuotaProjectId__) [GoogleCredentials.getUniverseDomain()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_getUniverseDomain__) [GoogleCredentials.hashCode()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_hashCode__) [GoogleCredentials.isExplicitUniverseDomain()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_isExplicitUniverseDomain__) [GoogleCredentials.newBuilder()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_newBuilder__) [GoogleCredentials.toBuilder()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_toBuilder__) [GoogleCredentials.toString()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_toString__) [GoogleCredentials.toStringHelper()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_toStringHelper__) [OAuth2Credentials.\<T\>getFromServiceLoader(Class\<? extends T\>,T)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials#com_google_auth_oauth2_OAuth2Credentials__T_getFromServiceLoader_java_lang_Class___extends_T__T_) [OAuth2Credentials.addChangeListener(OAuth2Credentials.CredentialsChangedListener)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials#com_google_auth_oauth2_OAuth2Credentials_addChangeListener_com_google_auth_oauth2_OAuth2Credentials_CredentialsChangedListener_) [OAuth2Credentials.getAccessToken()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials#com_google_auth_oauth2_OAuth2Credentials_getAccessToken__) [OAuth2Credentials.getAuthenticationType()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials#com_google_auth_oauth2_OAuth2Credentials_getAuthenticationType__) [OAuth2Credentials.getRequestMetadata(URI)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials#com_google_auth_oauth2_OAuth2Credentials_getRequestMetadata_java_net_URI_) [OAuth2Credentials.getRequestMetadata(URI,Executor,RequestMetadataCallback)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials#com_google_auth_oauth2_OAuth2Credentials_getRequestMetadata_java_net_URI_java_util_concurrent_Executor_com_google_auth_RequestMetadataCallback_) [OAuth2Credentials.getRequestMetadataInternal()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials#com_google_auth_oauth2_OAuth2Credentials_getRequestMetadataInternal__) [OAuth2Credentials.hasRequestMetadata()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials#com_google_auth_oauth2_OAuth2Credentials_hasRequestMetadata__) [OAuth2Credentials.hasRequestMetadataOnly()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials#com_google_auth_oauth2_OAuth2Credentials_hasRequestMetadataOnly__) [OAuth2Credentials.newInstance(String)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials#com_google_auth_oauth2_OAuth2Credentials_newInstance_java_lang_String_) [OAuth2Credentials.refresh()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials#com_google_auth_oauth2_OAuth2Credentials_refresh__) [OAuth2Credentials.refreshAccessToken()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials#com_google_auth_oauth2_OAuth2Credentials_refreshAccessToken__) [OAuth2Credentials.refreshIfExpired()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials#com_google_auth_oauth2_OAuth2Credentials_refreshIfExpired__) [OAuth2Credentials.removeChangeListener(OAuth2Credentials.CredentialsChangedListener)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials#com_google_auth_oauth2_OAuth2Credentials_removeChangeListener_com_google_auth_oauth2_OAuth2Credentials_CredentialsChangedListener_) [Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Methods

### fromStream(InputStream credentialsStream)

    public static GdchCredentials fromStream(InputStream credentialsStream)

Returns credentials defined by a GdchCredentials key file in JSON format from the Google
Developers Console.

Important: If you accept a credential configuration (credential JSON/File/Stream) from an
external source for authentication to Google Cloud Platform, you must validate it before
providing it to any Google API or library. Providing an unvalidated credential configuration to
Google APIs can compromise the security of your systems and data. For more information, refer
to {@see [documentation](https://cloud.google.com/docs/authentication/external/externally-sourced-credentials)}.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `credentialsStream` | `https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html` the stream with the credential definition. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GdchCredentials` | the credential defined by the credentialsStream. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` | if the credential cannot be created from the stream. |

### fromStream(InputStream credentialsStream, HttpTransportFactory transportFactory)

    public static GdchCredentials fromStream(InputStream credentialsStream, HttpTransportFactory transportFactory)

Returns credentials defined by a GdchCredentials key file in JSON format from the Google
Developers Console.

Important: If you accept a credential configuration (credential JSON/File/Stream) from an
external source for authentication to Google Cloud Platform, you must validate it before
providing it to any Google API or library. Providing an unvalidated credential configuration to
Google APIs can compromise the security of your systems and data. For more information, refer
to {@see [documentation](https://cloud.google.com/docs/authentication/external/externally-sourced-credentials)}.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `credentialsStream` | `https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html` the stream with the credential definition. |
| `transportFactory` | `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.http.HttpTransportFactory` HTTP transport factory, creates the transport used to get access tokens. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GdchCredentials` | the credential defined by the credentialsStream. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` | if the credential cannot be created from the stream. |

### newBuilder()

    public static GdchCredentials.Builder newBuilder()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GdchCredentials.Builder` |   |

## Methods

### createWithGdchAudience(String apiAudience)

    public GdchCredentials createWithGdchAudience(String apiAudience)

Create a copy of GDCH credentials with the specified audience.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `apiAudience` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The intended audience for GDCH credentials. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GdchCredentials` |   |

### createWithGdchAudience(URI apiAudience)

    public GdchCredentials createWithGdchAudience(URI apiAudience)

> [!WARNING]
> **Obsolete**
>
> *Use createWithGdchAudience(String) instead.*
>
> This feature is stable for usage in this major version, but may be deprecated in a future release.

This method is obsolete. Please use [#createWithGdchAudience(String)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GdchCredentials#com_google_auth_oauth2_GdchCredentials_createWithGdchAudience_java_lang_String_)} instead. Create a
copy of GDCH credentials with the specified audience.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `apiAudience` | `https://docs.oracle.com/javase/8/docs/api/java/net/URI.html` The intended audience for GDCH credentials. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GdchCredentials` |   |

### equals(Object obj)

    public boolean equals(Object obj)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `obj` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [GoogleCredentials.equals(Object obj)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_equals_java_lang_Object_)

### getApiAudience()

    public final URI getApiAudience()

> [!WARNING]
> **Obsolete**
>
> *Use getGdchAudience() instead.*
>
> This feature is stable for usage in this major version, but may be deprecated in a future release.

NOTE: This method is obsolete, please use [#getGdchAudience()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GdchCredentials#com_google_auth_oauth2_GdchCredentials_getGdchAudience__) instead. Returns a URI
representation of the underlying audience string set for this credentials object. This method
may fail if the underlying audience string does not conform to a URI format.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/net/URI.html` | a URI object representing the audience of the credentials, or null if no audience has been set or if the audience string is not a valid URI. |

### getCaCertPath()

    public final String getCaCertPath()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### getGdchAudience()

    public final String getGdchAudience()

Returns the underlying audience string set for this credentials object.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` | the audience string, or null if no audience has been set. |

### getPrivateKey()

    public final PrivateKey getPrivateKey()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/security/PrivateKey.html` |   |

### getPrivateKeyId()

    public final String getPrivateKeyId()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### getProjectId()

    public final String getProjectId()

The projectId value for a Credential type. Since not all GoogleCredentials subclass have a
projectId associated, the projectId may be null. A subset of GoogleCredentials subclasses will
override to return their projectId.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` | the projectId set in the GDCH SA Key file or the user set projectId |

**Overrides** [GoogleCredentials.getProjectId()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_getProjectId__)

### getServiceIdentityName()

    public final String getServiceIdentityName()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### getTokenServerUri()

    public final URI getTokenServerUri()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/net/URI.html` |   |

### getTransportFactory()

    public final HttpTransportFactory getTransportFactory()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.http.HttpTransportFactory` |   |

### hashCode()

    public int hashCode()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [GoogleCredentials.hashCode()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_hashCode__)

### refreshAccessToken()

    public AccessToken refreshAccessToken()

Refresh the OAuth2 access token by getting a new access token using a JSON Web Token (JWT).

For GDCH credentials, this class creates a self-signed JWT, and sends to the GDCH
authentication endpoint (tokenServerUri) to exchange an access token for the intended api
audience (apiAudience).

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.AccessToken` |   |

**Overrides** [OAuth2Credentials.refreshAccessToken()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials#com_google_auth_oauth2_OAuth2Credentials_refreshAccessToken__)

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### toBuilder()

    public GdchCredentials.Builder toBuilder()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GdchCredentials.Builder` |   |

**Overrides** [GoogleCredentials.toBuilder()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_toBuilder__)

### toString()

    public String toString()

Returns a string representation of this credential, including request metadata and access
token.

**Security Warning:** The output of this method includes the request metadata which
contains the raw Bearer access token, and the raw access token value. Do not log this output in
production environments as it may expose sensitive credentials.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

**Overrides** [GoogleCredentials.toString()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials#com_google_auth_oauth2_GoogleCredentials_toString__)