Class ExternalAccountCredentials
- All Implemented Interfaces:
QuotaProjectIdProvider,Serializable
- Direct Known Subclasses:
AwsCredentials,IdentityPoolCredentials,PluggableAuthCredentials
Handles initializing external credentials, calls to the Security Token Service, and service account impersonation.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBase builder for external account credentials.static enumEnum specifying values for the subjectTokenType field inExternalAccountCredentials.Nested classes/interfaces inherited from class com.google.auth.oauth2.OAuth2Credentials
OAuth2Credentials.CredentialsChangedListener -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ImpersonatedCredentialsprotected HttpTransportFactoryFields inherited from class com.google.auth.oauth2.GoogleCredentials
quotaProjectIdFields inherited from class com.google.auth.Credentials
GOOGLE_DEFAULT_UNIVERSE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedExternalAccountCredentials(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.protectedExternalAccountCredentials(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, EnvironmentProvider environmentProvider) Constructor with minimum identifying information and custom HTTP transport.protectedInternal constructor with minimum identifying information and custom HTTP transport. -
Method Summary
Modifier and TypeMethodDescriptionprotected AccessTokenexchangeExternalCredentialForAccessToken(StsTokenExchangeRequest stsTokenExchangeRequest) Exchanges the external credential for a Google Cloud access token.static ExternalAccountCredentialsfromStream(InputStream credentialsStream) Returns credentials defined by a JSON file stream.static ExternalAccountCredentialsfromStream(InputStream credentialsStream, HttpTransportFactory transportFactory) Returns credentials defined by a JSON file stream.com.google.auth.oauth2.ExternalAccountCredentials.CredentialSourcegetRequestMetadata(URI uri) Provide the request metadata by ensuring there is a current access token and providing it as an authorization bearer token.voidgetRequestMetadata(URI uri, Executor executor, RequestMetadataCallback callback) com.google.auth.oauth2.ExternalAccountCredentials.ServiceAccountImpersonationOptionsGets the universe domain for the credential.booleanabstract StringRetrieves the external subject token to be exchanged for a Google Cloud access token.Methods inherited from class com.google.auth.oauth2.GoogleCredentials
create, create, createDelegated, createScoped, createScoped, createScoped, createScopedRequired, createWithCustomRetryStrategy, createWithQuotaProject, equals, getAdditionalHeaders, getApplicationDefault, getApplicationDefault, getCredentialInfo, getProjectId, getQuotaProjectId, hashCode, isExplicitUniverseDomain, newBuilder, toBuilder, toString, toStringHelperMethods inherited from class com.google.auth.oauth2.OAuth2Credentials
addChangeListener, getAccessToken, getAuthenticationType, getFromServiceLoader, getRequestMetadataInternal, hasRequestMetadata, hasRequestMetadataOnly, newInstance, refresh, refreshAccessToken, refreshIfExpired, removeChangeListenerMethods inherited from class com.google.auth.Credentials
blockingGetToCallback, getMetricsCredentialType, getRequestMetadata
-
Field Details
-
transportFactory
-
impersonatedCredentials
-
-
Constructor Details
-
ExternalAccountCredentials
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) Constructor with minimum identifying information and custom HTTP transport. Does not support workforce credentials.- Parameters:
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.
-
ExternalAccountCredentials
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 EnvironmentProvider environmentProvider) Constructor with minimum identifying information and custom HTTP transport. Does not support workforce credentials.- Parameters:
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 toSystemEnvironmentProvider.
-
ExternalAccountCredentials
Internal constructor with minimum identifying information and custom HTTP transport. SeeExternalAccountCredentials.Builder.- Parameters:
builder- theBuilderobject used to construct the credentials.
-
-
Method Details
-
getRequestMetadata
- Overrides:
getRequestMetadatain classOAuth2Credentials
-
getUniverseDomain
Description copied from class:GoogleCredentialsGets the universe domain for the credential.- Overrides:
getUniverseDomainin classGoogleCredentials- Returns:
- An explicit universe domain if it was explicitly provided, invokes the super implementation otherwise
-
getRequestMetadata
Description copied from class:OAuth2CredentialsProvide the request metadata by ensuring there is a current access token and providing it as an authorization bearer token.- Overrides:
getRequestMetadatain classOAuth2Credentials- Throws:
IOException
-
fromStream
public static ExternalAccountCredentials fromStream(InputStream credentialsStream) throws IOException Returns credentials defined by a JSON file stream.Returns
IdentityPoolCredentialsorAwsCredentials.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 .
- Parameters:
credentialsStream- the stream with the credential definition- Returns:
- the credential defined by the credentialsStream
- Throws:
IOException- if the credential cannot be created from the stream
-
fromStream
public static ExternalAccountCredentials fromStream(InputStream credentialsStream, HttpTransportFactory transportFactory) throws IOException Returns credentials defined by a JSON file stream.Returns a
IdentityPoolCredentialsorAwsCredentials.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 .
- Parameters:
credentialsStream- the stream with the credential definitiontransportFactory- the HTTP transport factory used to create the transport to get access tokens- Returns:
- the credential defined by the credentialsStream
- Throws:
IOException- if the credential cannot be created from the stream
-
exchangeExternalCredentialForAccessToken
protected AccessToken exchangeExternalCredentialForAccessToken(StsTokenExchangeRequest stsTokenExchangeRequest) throws IOException Exchanges the external credential for a Google Cloud access token.- Parameters:
stsTokenExchangeRequest- the Security Token Service token exchange request- Returns:
- the access token returned by the Security Token Service
- Throws:
com.google.auth.oauth2.OAuthException- if the call to the Security Token Service failsIOException
-
retrieveSubjectToken
Retrieves the external subject token to be exchanged for a Google Cloud access token.Must be implemented by subclasses as the retrieval method is dependent on the credential source.
- Returns:
- the external subject token
- Throws:
IOException- if the subject token cannot be retrieved
-
getAudience
-
getSubjectTokenType
-
getTokenUrl
-
getTokenInfoUrl
-
getCredentialSource
public com.google.auth.oauth2.ExternalAccountCredentials.CredentialSource getCredentialSource() -
getServiceAccountImpersonationUrl
-
getServiceAccountEmail
- Returns:
- The service account email to be impersonated, if available
-
getClientId
-
getClientSecret
-
getScopes
-
getWorkforcePoolUserProject
-
getServiceAccountImpersonationOptions
@Nullable public com.google.auth.oauth2.ExternalAccountCredentials.ServiceAccountImpersonationOptions getServiceAccountImpersonationOptions() -
isWorkforcePoolConfiguration
public boolean isWorkforcePoolConfiguration()- Returns:
- whether the current configuration is for Workforce Pools (which enable 3p user identities, rather than workloads)
-