public abstract class ExternalAccountCredentials extends GoogleCredentials
Handles initializing external credentials, calls to the Security Token Service, and service account impersonation.
| Modifier and Type | Class and Description |
|---|---|
static class |
ExternalAccountCredentials.Builder
Base builder for external account credentials.
|
static class |
ExternalAccountCredentials.SubjectTokenTypes
Enum specifying values for the subjectTokenType field in
ExternalAccountCredentials. |
OAuth2Credentials.CredentialsChangedListener| Modifier and Type | Field and Description |
|---|---|
protected ImpersonatedCredentials |
impersonatedCredentials |
protected HttpTransportFactory |
transportFactory |
quotaProjectIdGOOGLE_DEFAULT_UNIVERSE| Modifier | Constructor and Description |
|---|---|
protected |
ExternalAccountCredentials(ExternalAccountCredentials.Builder builder)
Internal constructor with minimum identifying information and custom HTTP transport.
|
protected |
ExternalAccountCredentials(HttpTransportFactory transportFactory,
String audience,
String subjectTokenType,
String tokenUrl,
com.google.auth.oauth2.ExternalAccountCredentials.CredentialSource credentialSource,
String tokenInfoUrl,
String serviceAccountImpersonationUrl,
String quotaProjectId,
String clientId,
String clientSecret,
Collection<String> scopes)
Constructor with minimum identifying information and custom HTTP transport.
|
protected |
ExternalAccountCredentials(HttpTransportFactory transportFactory,
String audience,
String subjectTokenType,
String tokenUrl,
com.google.auth.oauth2.ExternalAccountCredentials.CredentialSource credentialSource,
String tokenInfoUrl,
String serviceAccountImpersonationUrl,
String quotaProjectId,
String clientId,
String clientSecret,
Collection<String> scopes,
com.google.auth.oauth2.EnvironmentProvider environmentProvider)
Constructor with minimum identifying information and custom HTTP transport.
|
create, create, createDelegated, createScoped, createScoped, createScoped, createScopedRequired, createWithCustomRetryStrategy, createWithQuotaProject, equals, getAdditionalHeaders, getApplicationDefault, getApplicationDefault, getCredentialInfo, getQuotaProjectId, hashCode, isExplicitUniverseDomain, newBuilder, toBuilder, toString, toStringHelperaddChangeListener, getAccessToken, getAuthenticationType, getFromServiceLoader, getRequestMetadataInternal, hasRequestMetadata, hasRequestMetadataOnly, newInstance, refresh, refreshAccessToken, refreshIfExpired, removeChangeListenerblockingGetToCallback, getMetricsCredentialType, getRequestMetadataprotected transient HttpTransportFactory transportFactory
@Nullable protected ImpersonatedCredentials impersonatedCredentials
protected ExternalAccountCredentials(HttpTransportFactory transportFactory, String audience, String subjectTokenType, String tokenUrl, com.google.auth.oauth2.ExternalAccountCredentials.CredentialSource credentialSource, @Nullable String tokenInfoUrl, @Nullable String serviceAccountImpersonationUrl, @Nullable String quotaProjectId, @Nullable String clientId, @Nullable String clientSecret, @Nullable Collection<String> scopes)
transportFactory - HTTP transport factory, creates the transport used to get access tokensaudience - the Security Token Service audience, which is usually the fully specified
resource name of the workload/workforce pool providersubjectTokenType - 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 filetokenUrl - the Security Token Service token exchange endpointtokenInfoUrl - the endpoint used to retrieve account related information. Required for
gCloud session account identification.credentialSource - the external credential sourceserviceAccountImpersonationUrl - the URL for the service account impersonation request.
This URL is required for some APIs. If this URL is not available, the access token from the
Security Token Service is used directly. May be null.quotaProjectId - the project used for quota and billing purposes. May be null.clientId - client ID of the service account from the console. May be null.clientSecret - client secret of the service account from the console. May be null.scopes - the scopes to request during the authorization grant. May be null.protected ExternalAccountCredentials(HttpTransportFactory transportFactory, String audience, String subjectTokenType, String tokenUrl, com.google.auth.oauth2.ExternalAccountCredentials.CredentialSource credentialSource, @Nullable String tokenInfoUrl, @Nullable String serviceAccountImpersonationUrl, @Nullable String quotaProjectId, @Nullable String clientId, @Nullable String clientSecret, @Nullable Collection<String> scopes, @Nullable com.google.auth.oauth2.EnvironmentProvider environmentProvider)
transportFactory - HTTP transport factory, creates the transport used to get access tokensaudience - the Security Token Service audience, which is usually the fully specified
resource name of the workload/workforce pool providersubjectTokenType - 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 filetokenUrl - the Security Token Service token exchange endpointtokenInfoUrl - the endpoint used to retrieve account related information. Required for
gCloud session account identification.credentialSource - the external credential sourceserviceAccountImpersonationUrl - the URL for the service account impersonation request.
This URL is required for some APIs. If this URL is not available, the access token from the
Security Token Service is used directly. May be null.quotaProjectId - the project used for quota and billing purposes. May be null.clientId - client ID of the service account from the console. May be null.clientSecret - client secret of the service account from the console. May be null.scopes - the scopes to request during the authorization grant. May be null.environmentProvider - the environment provider. May be null. Defaults to SystemEnvironmentProvider.protected ExternalAccountCredentials(ExternalAccountCredentials.Builder builder)
ExternalAccountCredentials.Builder.builder - the Builder object used to construct the credentials.public void getRequestMetadata(URI uri, Executor executor, RequestMetadataCallback callback)
getRequestMetadata in class OAuth2Credentialspublic String getUniverseDomain()
GoogleCredentialsgetUniverseDomain in class GoogleCredentialspublic Map<String,List<String>> getRequestMetadata(URI uri) throws IOException
OAuth2CredentialsgetRequestMetadata in class OAuth2CredentialsIOExceptionpublic static ExternalAccountCredentials fromStream(InputStream credentialsStream) throws IOException
Returns IdentityPoolCredentials or AwsCredentials.
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 documentation.
credentialsStream - the stream with the credential definitionIOException - if the credential cannot be created from the streampublic static ExternalAccountCredentials fromStream(InputStream credentialsStream, HttpTransportFactory transportFactory) throws IOException
Returns a IdentityPoolCredentials or AwsCredentials.
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 documentation.
credentialsStream - the stream with the credential definitiontransportFactory - the HTTP transport factory used to create the transport to get access
tokensIOException - if the credential cannot be created from the streamprotected AccessToken exchangeExternalCredentialForAccessToken(StsTokenExchangeRequest stsTokenExchangeRequest) throws IOException
stsTokenExchangeRequest - the Security Token Service token exchange requestOAuthException - if the call to the Security Token Service failsIOExceptionpublic abstract String retrieveSubjectToken() throws IOException
Must be implemented by subclasses as the retrieval method is dependent on the credential source.
IOException - if the subject token cannot be retrievedpublic String getAudience()
public String getSubjectTokenType()
public String getTokenUrl()
public String getTokenInfoUrl()
public com.google.auth.oauth2.ExternalAccountCredentials.CredentialSource getCredentialSource()
@Nullable public String getServiceAccountEmail()
@Nullable public Collection<String> getScopes()
@Nullable public com.google.auth.oauth2.ExternalAccountCredentials.ServiceAccountImpersonationOptions getServiceAccountImpersonationOptions()
public boolean isWorkforcePoolConfiguration()
Copyright © 2025 Google. All rights reserved.