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.
|
OAuth2Credentials.CredentialsChangedListener
Modifier and Type | Field and Description |
---|---|
protected ImpersonatedCredentials |
impersonatedCredentials |
protected HttpTransportFactory |
transportFactory |
quotaProjectId
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.
|
Modifier and Type | Method and Description |
---|---|
protected AccessToken |
exchangeExternalCredentialForAccessToken(com.google.auth.oauth2.StsTokenExchangeRequest stsTokenExchangeRequest)
Exchanges the external credential for a Google Cloud access token.
|
static ExternalAccountCredentials |
fromStream(InputStream credentialsStream)
Returns credentials defined by a JSON file stream.
|
static ExternalAccountCredentials |
fromStream(InputStream credentialsStream,
HttpTransportFactory transportFactory)
Returns credentials defined by a JSON file stream.
|
String |
getAudience() |
String |
getClientId() |
String |
getClientSecret() |
com.google.auth.oauth2.ExternalAccountCredentials.CredentialSource |
getCredentialSource() |
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.
|
void |
getRequestMetadata(URI uri,
Executor executor,
RequestMetadataCallback callback)
Get the current request metadata without blocking.
|
Collection<String> |
getScopes() |
String |
getServiceAccountEmail() |
com.google.auth.oauth2.ExternalAccountCredentials.ServiceAccountImpersonationOptions |
getServiceAccountImpersonationOptions() |
String |
getServiceAccountImpersonationUrl() |
String |
getSubjectTokenType() |
String |
getTokenInfoUrl() |
String |
getTokenUrl() |
String |
getWorkforcePoolUserProject() |
boolean |
isWorkforcePoolConfiguration() |
abstract String |
retrieveSubjectToken()
Retrieves the external subject token to be exchanged for a Google Cloud access token.
|
create, createDelegated, createScoped, createScoped, createScoped, createScopedRequired, createWithCustomRetryStrategy, createWithQuotaProject, getAdditionalHeaders, getApplicationDefault, getApplicationDefault, getQuotaProjectId, newBuilder, toBuilder
addChangeListener, equals, getAccessToken, getAuthenticationType, getFromServiceLoader, getRequestMetadataInternal, hashCode, hasRequestMetadata, hasRequestMetadataOnly, newInstance, refresh, refreshAccessToken, refreshIfExpired, removeChangeListener, toString
blockingGetToCallback, getRequestMetadata
protected transient HttpTransportFactory transportFactory
@Nullable protected final 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)
Credentials
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 Credentials.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.
getRequestMetadata
in class OAuth2Credentials
uri
- URI of the entry point for the request.executor
- Executor to perform the request.callback
- Callback to execute when the request is finished.public Map<String,List<String>> getRequestMetadata(URI uri) throws IOException
OAuth2Credentials
getRequestMetadata
in class OAuth2Credentials
uri
- URI of the entry point for the request.IOException
- if there was an error getting up-to-date access. The exception should
implement Retryable
and isRetryable()
will return true if the operation may
be retried.public static ExternalAccountCredentials fromStream(InputStream credentialsStream) throws IOException
Returns IdentityPoolCredentials
or AwsCredentials
.
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
.
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(com.google.auth.oauth2.StsTokenExchangeRequest stsTokenExchangeRequest) throws IOException
stsTokenExchangeRequest
- the Security Token Service token exchange requestOAuthException
- if the call to the Security Token Service failsIOException
public 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 © 2023 Google. All rights reserved.