# Class ExternalAccountCredentials.Builder (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 abstract static class ExternalAccountCredentials.Builder extends GoogleCredentials.Builder

Base builder for external account credentials.

## Inheritance

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

## Inherited Members

[GoogleCredentials.Builder.build()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.Builder#com_google_auth_oauth2_GoogleCredentials_Builder_build__) [GoogleCredentials.Builder.getQuotaProjectId()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.Builder#com_google_auth_oauth2_GoogleCredentials_Builder_getQuotaProjectId__) [GoogleCredentials.Builder.getUniverseDomain()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.Builder#com_google_auth_oauth2_GoogleCredentials_Builder_getUniverseDomain__) [GoogleCredentials.Builder.setAccessToken(AccessToken)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.Builder#com_google_auth_oauth2_GoogleCredentials_Builder_setAccessToken_com_google_auth_oauth2_AccessToken_) [GoogleCredentials.Builder.setQuotaProjectId(String)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.Builder#com_google_auth_oauth2_GoogleCredentials_Builder_setQuotaProjectId_java_lang_String_) [GoogleCredentials.Builder.setUniverseDomain(String)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.Builder#com_google_auth_oauth2_GoogleCredentials_Builder_setUniverseDomain_java_lang_String_) [OAuth2Credentials.Builder.getAccessToken()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials.Builder#com_google_auth_oauth2_OAuth2Credentials_Builder_getAccessToken__) [OAuth2Credentials.Builder.getExpirationMargin()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials.Builder#com_google_auth_oauth2_OAuth2Credentials_Builder_getExpirationMargin__) [OAuth2Credentials.Builder.getRefreshMargin()](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials.Builder#com_google_auth_oauth2_OAuth2Credentials_Builder_getRefreshMargin__) [OAuth2Credentials.Builder.setExpirationMargin(Duration)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials.Builder#com_google_auth_oauth2_OAuth2Credentials_Builder_setExpirationMargin_java_time_Duration_) [OAuth2Credentials.Builder.setRefreshMargin(Duration)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.OAuth2Credentials.Builder#com_google_auth_oauth2_OAuth2Credentials_Builder_setRefreshMargin_java_time_Duration_) [Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [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.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [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.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [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-)

## Constructors

### Builder()

    protected Builder()

### Builder(ExternalAccountCredentials credentials)

    protected Builder(ExternalAccountCredentials credentials)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `credentials` | `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.ExternalAccountCredentials` |

## Fields

### audience

    protected String audience

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

### clientId

    protected String clientId

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

### clientSecret

    protected String clientSecret

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

### connectTimeout

    protected int connectTimeout

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

### credentialSource

    protected ExternalAccountCredentials.CredentialSource credentialSource

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `com.google.auth.oauth2.ExternalAccountCredentials.CredentialSource` |   |

### environmentProvider

    protected EnvironmentProvider environmentProvider

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

### metricsHandler

    protected ExternalAccountMetricsHandler metricsHandler

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `com.google.auth.oauth2.ExternalAccountMetricsHandler` |   |

### propertyProvider

    protected PropertyProvider propertyProvider

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

### readTimeout

    protected int readTimeout

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

### scopes

    protected Collection<String> scopes

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` |   |

### serviceAccountImpersonationOptions

    protected ExternalAccountCredentials.ServiceAccountImpersonationOptions serviceAccountImpersonationOptions

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `com.google.auth.oauth2.ExternalAccountCredentials.ServiceAccountImpersonationOptions` |   |

### serviceAccountImpersonationUrl

    protected String serviceAccountImpersonationUrl

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

### subjectTokenType

    protected String subjectTokenType

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

### tokenInfoUrl

    protected String tokenInfoUrl

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

### tokenUrl

    protected String tokenUrl

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

### transportFactory

    protected HttpTransportFactory transportFactory

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

### universeDomain (deprecated)

    protected String universeDomain

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

### workforcePoolUserProject

    protected String workforcePoolUserProject

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

## Methods

### build()

    public abstract ExternalAccountCredentials build()

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

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

### setAudience(String audience)

    public ExternalAccountCredentials.Builder setAudience(String audience)

Sets the Security Token Service audience, which is usually the fully specified resource name
of the workload/workforce pool provider.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `audience` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` the Security Token Service audience to set |

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

### setClientId(String clientId)

    public ExternalAccountCredentials.Builder setClientId(String clientId)

Sets the optional client ID of the service account from the console.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `clientId` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` the service account client id to set |

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

### setClientSecret(String clientSecret)

    public ExternalAccountCredentials.Builder setClientSecret(String clientSecret)

Sets the optional client secret of the service account from the console.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `clientSecret` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` the service account client secret to set |

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

### setConnectTimeout(int connectTimeout)

    public ExternalAccountCredentials.Builder setConnectTimeout(int connectTimeout)

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

Warning: Not for public use and can be removed at any time.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `connectTimeout` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

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

### setCredentialSource(ExternalAccountCredentials.CredentialSource credentialSource)

    public ExternalAccountCredentials.Builder setCredentialSource(ExternalAccountCredentials.CredentialSource credentialSource)

Sets the external credential source.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `credentialSource` | `com.google.auth.oauth2.ExternalAccountCredentials.CredentialSource` the `CredentialSource` to set |

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

### setHttpTransportFactory(HttpTransportFactory transportFactory)

    public ExternalAccountCredentials.Builder setHttpTransportFactory(HttpTransportFactory transportFactory)

Sets the HTTP transport factory, creates the transport used to get access tokens.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `transportFactory` | `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.http.HttpTransportFactory` the `HttpTransportFactory` to set |

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

### setQuotaProjectId(String quotaProjectId)

    public ExternalAccountCredentials.Builder setQuotaProjectId(String quotaProjectId)

Sets the optional project used for quota and billing purposes.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `quotaProjectId` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` the quota and billing project id to set |

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

**Overrides** [GoogleCredentials.Builder.setQuotaProjectId(String quotaProjectId)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.Builder#com_google_auth_oauth2_GoogleCredentials_Builder_setQuotaProjectId_java_lang_String_)

### setReadTimeout(int readTimeout)

    public ExternalAccountCredentials.Builder setReadTimeout(int readTimeout)

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

Warning: Not for public use and can be removed at any time.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `readTimeout` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

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

### setScopes(Collection\<String\> scopes)

    public ExternalAccountCredentials.Builder setScopes(Collection<String> scopes)

Sets the optional scopes to request during the authorization grant.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `scopes` | `https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` the request scopes to set |

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

### setServiceAccountImpersonationOptions(Map\<String,Object\> optionsMap)

    public ExternalAccountCredentials.Builder setServiceAccountImpersonationOptions(Map<String,Object> optionsMap)

Sets the optional service account impersonation options.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `optionsMap` | `https://docs.oracle.com/javase/8/docs/api/java/util/Map.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html,https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html>` the service account impersonation options to set |

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

### setServiceAccountImpersonationUrl(String serviceAccountImpersonationUrl)

    public ExternalAccountCredentials.Builder setServiceAccountImpersonationUrl(String serviceAccountImpersonationUrl)

Sets the optional URL used for service account impersonation, which is required for some
APIs. If this URL is not available, the access token from the Security Token Service is used
directly.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `serviceAccountImpersonationUrl` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` the service account impersonation url to set |

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

### setSubjectTokenType(ExternalAccountCredentials.SubjectTokenTypes subjectTokenType)

    public ExternalAccountCredentials.Builder setSubjectTokenType(ExternalAccountCredentials.SubjectTokenTypes subjectTokenType)

Sets the Security Token Service subject token type based on the OAuth 2.0 token exchange
spec. Indicates the type of the security token in the credential file.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `subjectTokenType` | `https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.ExternalAccountCredentials.SubjectTokenTypes` the `SubjectTokenType` to set |

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

### setSubjectTokenType(String subjectTokenType)

    public ExternalAccountCredentials.Builder setSubjectTokenType(String subjectTokenType)

Sets the Security Token Service subject token type based on the OAuth 2.0 token exchange
spec. Indicates the type of the security token in the credential file.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `subjectTokenType` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` the Security Token Service subject token type to set |

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

### setTokenInfoUrl(String tokenInfoUrl)

    public ExternalAccountCredentials.Builder setTokenInfoUrl(String tokenInfoUrl)

Sets the optional endpoint used to retrieve account related information. Required for gCloud
session account identification.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `tokenInfoUrl` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` the token info url to set |

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

### setTokenUrl(String tokenUrl)

    public ExternalAccountCredentials.Builder setTokenUrl(String tokenUrl)

Sets the Security Token Service token exchange endpoint.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `tokenUrl` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` the Security Token Service token exchange url to set |

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

### setUniverseDomain(String universeDomain)

    public ExternalAccountCredentials.Builder setUniverseDomain(String universeDomain)

Sets the optional universe domain.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `universeDomain` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` the universe domain to set |

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

**Overrides** [GoogleCredentials.Builder.setUniverseDomain(String universeDomain)](https://docs.cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.Builder#com_google_auth_oauth2_GoogleCredentials_Builder_setUniverseDomain_java_lang_String_)

### setWorkforcePoolUserProject(String workforcePoolUserProject)

    public ExternalAccountCredentials.Builder setWorkforcePoolUserProject(String workforcePoolUserProject)

Sets the optional workforce pool user project number when the credential corresponds to a
workforce pool and not a workload identity pool. The underlying principal must still have
serviceusage.services.use IAM permission to use the project for billing/quota.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `workforcePoolUserProject` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` the workforce pool user project number to set |

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