public abstract class ExternalAccountCredentials extends GoogleCredentials implements QuotaProjectIdProvider
Base external account credentials class.
Handles initializing external credentials, calls to STS, and service account impersonation.
Inheritance
java.lang.Object > Credentials > OAuth2Credentials > GoogleCredentials > ExternalAccountCredentialsImplements
QuotaProjectIdProviderConstructors
ExternalAccountCredentials(HttpTransportFactory transportFactory, String audience, String subjectTokenType, String tokenUrl, ExternalAccountCredentials.CredentialSource credentialSource, String tokenInfoUrl, String serviceAccountImpersonationUrl, String quotaProjectId, String clientId, String clientSecret, Collection<String> scopes)
protected ExternalAccountCredentials(HttpTransportFactory transportFactory, String audience, String subjectTokenType, String tokenUrl, 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. Does not support workforce credentials.
Name | Description |
transportFactory | HttpTransportFactory HTTP transport factory, creates the transport used to get access tokens |
audience | String the STS audience which is usually the fully specified resource name of the workload/workforce pool provider |
subjectTokenType | String the STS subject token type based on the OAuth 2.0 token exchange spec. Indicates the type of the security token in the credential file |
tokenUrl | String the STS token exchange endpoint |
credentialSource | com.google.auth.oauth2.ExternalAccountCredentials.CredentialSource the external credential source |
tokenInfoUrl | String the endpoint used to retrieve account related information. Required for gCloud session account identification. |
serviceAccountImpersonationUrl | String the URL for the service account impersonation request. This is only required for workload identity pools when APIs to be accessed have not integrated with UberMint. If this is not available, the STS returned GCP access token is directly used. May be null. |
quotaProjectId | String the project used for quota and billing purposes. May be null. |
clientId | String client ID of the service account from the console. May be null. |
clientSecret | String client secret of the service account from the console. May be null. |
scopes | Collection<String> the scopes to request during the authorization grant. May be null. |
ExternalAccountCredentials(HttpTransportFactory transportFactory, String audience, String subjectTokenType, String tokenUrl, ExternalAccountCredentials.CredentialSource credentialSource, String tokenInfoUrl, String serviceAccountImpersonationUrl, String quotaProjectId, String clientId, String clientSecret, Collection<String> scopes, EnvironmentProvider environmentProvider)
protected ExternalAccountCredentials(HttpTransportFactory transportFactory, String audience, String subjectTokenType, String tokenUrl, ExternalAccountCredentials.CredentialSource credentialSource, String tokenInfoUrl, String serviceAccountImpersonationUrl, String quotaProjectId, String clientId, String clientSecret, Collection<String> scopes, EnvironmentProvider environmentProvider)
See ExternalAccountCredentials#ExternalAccountCredentials(HttpTransportFactory, String, String, String, CredentialSource, String, String, String, String, String, Collection)
Name | Description |
transportFactory | HttpTransportFactory |
audience | String |
subjectTokenType | String |
tokenUrl | String |
credentialSource | com.google.auth.oauth2.ExternalAccountCredentials.CredentialSource |
tokenInfoUrl | String |
serviceAccountImpersonationUrl | String |
quotaProjectId | String |
clientId | String |
clientSecret | String |
scopes | Collection<String> |
environmentProvider | com.google.auth.oauth2.EnvironmentProvider the environment provider. May be null. Defaults to SystemEnvironmentProvider. |
ExternalAccountCredentials(ExternalAccountCredentials.Builder builder)
protected ExternalAccountCredentials(ExternalAccountCredentials.Builder builder)
Internal constructor with minimum identifying information and custom HTTP transport. See ExternalAccountCredentials.Builder.
Name | Description |
builder | ExternalAccountCredentials.Builder |
Fields
impersonatedCredentials
protected final ImpersonatedCredentials impersonatedCredentials
Type | Description |
ImpersonatedCredentials |
transportFactory
protected transient HttpTransportFactory transportFactory
Type | Description |
HttpTransportFactory |
Methods
exchangeExternalCredentialForAccessToken(StsTokenExchangeRequest stsTokenExchangeRequest)
protected AccessToken exchangeExternalCredentialForAccessToken(StsTokenExchangeRequest stsTokenExchangeRequest)
Exchanges the external credential for a GCP access token.
Name | Description |
stsTokenExchangeRequest | com.google.auth.oauth2.StsTokenExchangeRequest the STS token exchange request |
Type | Description |
AccessToken | the access token returned by STS |
Type | Description |
IOException | if the call to STS fails |
fromStream(InputStream credentialsStream)
public static ExternalAccountCredentials fromStream(InputStream credentialsStream)
Returns credentials defined by a JSON file stream.
Returns IdentityPoolCredentials or AwsCredentials.
Name | Description |
credentialsStream | InputStream the stream with the credential definition |
Type | Description |
ExternalAccountCredentials | the credential defined by the credentialsStream |
Type | Description |
IOException | if the credential cannot be created from the stream |
fromStream(InputStream credentialsStream, HttpTransportFactory transportFactory)
public static ExternalAccountCredentials fromStream(InputStream credentialsStream, HttpTransportFactory transportFactory)
Returns credentials defined by a JSON file stream.
Returns a IdentityPoolCredentials or AwsCredentials.
Name | Description |
credentialsStream | InputStream the stream with the credential definition |
transportFactory | HttpTransportFactory the HTTP transport factory used to create the transport to get access tokens |
Type | Description |
ExternalAccountCredentials | the credential defined by the credentialsStream |
Type | Description |
IOException | if the credential cannot be created from the stream |
getAudience()
public String getAudience()
Type | Description |
String |
getClientId()
public String getClientId()
Type | Description |
String |
getClientSecret()
public String getClientSecret()
Type | Description |
String |
getCredentialSource()
public ExternalAccountCredentials.CredentialSource getCredentialSource()
Type | Description |
com.google.auth.oauth2.ExternalAccountCredentials.CredentialSource |
getQuotaProjectId()
public String getQuotaProjectId()
Type | Description |
String |
getRequestMetadata(URI uri)
public Map<String,List<String>> getRequestMetadata(URI uri)
Provide the request metadata by ensuring there is a current access token and providing it as an authorization bearer token.
Name | Description |
uri | URI |
Type | Description |
Map<String,List<String>> |
Type | Description |
IOException |
getRequestMetadata(URI uri, Executor executor, RequestMetadataCallback callback)
public void getRequestMetadata(URI uri, Executor executor, RequestMetadataCallback callback)
Get the current request metadata without blocking.
This should be called by the transport layer on each request, and the data should be populated in headers or other context. The implementation can either call the callback inline or asynchronously. Either way it should never block in this method. The executor is provided for tasks that may block.
The default implementation will just call #getRequestMetadata(URI) then the callback from the given executor.
The convention for handling binary data is for the key in the returned map to end with
"-bin"
and for the corresponding values to be base64 encoded.
Name | Description |
uri | URI |
executor | Executor |
callback | RequestMetadataCallback |
getScopes()
public Collection<String> getScopes()
Type | Description |
Collection<String> |
getServiceAccountImpersonationUrl()
public String getServiceAccountImpersonationUrl()
Type | Description |
String |
getSubjectTokenType()
public String getSubjectTokenType()
Type | Description |
String |
getTokenInfoUrl()
public String getTokenInfoUrl()
Type | Description |
String |
getTokenUrl()
public String getTokenUrl()
Type | Description |
String |
getWorkforcePoolUserProject()
public String getWorkforcePoolUserProject()
Type | Description |
String |
isWorkforcePoolConfiguration()
public boolean isWorkforcePoolConfiguration()
Returns whether or not the current configuration is for Workforce Pools (which enable 3p user identities, rather than workloads).
Type | Description |
boolean |
retrieveSubjectToken()
public abstract String retrieveSubjectToken()
Retrieves the external subject token to be exchanged for a GCP access token.
Must be implemented by subclasses as the retrieval method is dependent on the credential source.
Type | Description |
String | the external subject token |
Type | Description |
IOException |