public class ComputeEngineCredentials extends GoogleCredentials implements ServiceAccountSigner, IdTokenProvider
Fetches access tokens from the Google Compute Engine metadata server.
These credentials use the IAM API to sign data. See sign(byte[]) for more details.
| Modifier and Type | Class and Description |
|---|---|
static class |
ComputeEngineCredentials.BindingEnforcement
Experimental Feature.
|
static class |
ComputeEngineCredentials.Builder |
static class |
ComputeEngineCredentials.GoogleAuthTransport
Experimental Feature.
|
OAuth2Credentials.CredentialsChangedListenerServiceAccountSigner.SigningExceptionIdTokenProvider.OptionquotaProjectIdGOOGLE_DEFAULT_UNIVERSE| Modifier and Type | Method and Description |
|---|---|
static ComputeEngineCredentials |
create()
Create a new ComputeEngineCredentials instance with default behavior.
|
GoogleCredentials |
createScoped(Collection<String> newScopes)
Clones the compute engine account with the specified scopes.
|
GoogleCredentials |
createScoped(Collection<String> newScopes,
Collection<String> newDefaultScopes)
Clones the compute engine account with the specified scopes and default scopes.
|
boolean |
equals(Object obj) |
String |
getAccount()
Returns the email address associated with the GCE default service account.
|
static String |
getIdentityDocumentUrl() |
static String |
getMetadataServerUrl() |
static String |
getMetadataServerUrl(com.google.auth.oauth2.DefaultCredentialsProvider provider) |
CredentialTypeForMetrics |
getMetricsCredentialType() |
Collection<String> |
getScopes() |
static String |
getServiceAccountsUrl() |
static String |
getTokenServerEncodedUrl() |
static String |
getTokenServerEncodedUrl(com.google.auth.oauth2.DefaultCredentialsProvider provider) |
String |
getUniverseDomain()
Gets the universe domain from the GCE metadata server.
|
static String |
getUniverseDomainUrl() |
int |
hashCode() |
IdToken |
idTokenWithAudience(String targetAudience,
List<IdTokenProvider.Option> options)
Returns a Google ID Token from the metadata server on ComputeEngine
|
static ComputeEngineCredentials.Builder |
newBuilder() |
AccessToken |
refreshAccessToken()
Refresh the access token by getting it from the GCE metadata server
|
byte[] |
sign(byte[] toSign)
Signs the provided bytes using the private key associated with the service account.
|
ComputeEngineCredentials.Builder |
toBuilder() |
protected com.google.common.base.MoreObjects.ToStringHelper |
toStringHelper()
A helper for overriding the toString() method.
|
create, create, createDelegated, createScoped, createScopedRequired, createWithCustomRetryStrategy, createWithQuotaProject, fromStream, fromStream, getAdditionalHeaders, getApplicationDefault, getApplicationDefault, getCredentialInfo, getProjectId, getQuotaProjectId, isExplicitUniverseDomain, toStringaddChangeListener, getAccessToken, getAuthenticationType, getFromServiceLoader, getRequestMetadata, getRequestMetadata, getRequestMetadataInternal, hasRequestMetadata, hasRequestMetadataOnly, newInstance, refresh, refreshIfExpired, removeChangeListenerblockingGetToCallback, getRequestMetadatapublic CredentialTypeForMetrics getMetricsCredentialType()
getMetricsCredentialType in class Credentialspublic GoogleCredentials createScoped(Collection<String> newScopes)
createScoped in class GoogleCredentialsnewScopes - Collection of scopes to request.public GoogleCredentials createScoped(Collection<String> newScopes, Collection<String> newDefaultScopes)
createScoped in class GoogleCredentialsnewScopes - Collection of scopes to request.newDefaultScopes - Collection of default scopes to request.public static ComputeEngineCredentials create()
public final Collection<String> getScopes()
public String getUniverseDomain() throws IOException
Returns an explicit universe domain if it was provided during credential initialization.
Returns the Credentials.GOOGLE_DEFAULT_UNIVERSE if universe domain endpoint is not
found (404) or returns an empty string.
Otherwise, returns universe domain from GCE metadata service.
Any above value is cached for the credential lifetime.
getUniverseDomain in class GoogleCredentialsIOException - if a call to GCE metadata service was unsuccessful. Check if exception
implements the Retryable and isRetryable() will return true if the
operation may be retried.public AccessToken refreshAccessToken() throws IOException
refreshAccessToken in class OAuth2CredentialsIOExceptionpublic IdToken idTokenWithAudience(String targetAudience, List<IdTokenProvider.Option> options) throws IOException
idTokenWithAudience in interface IdTokenProvidertargetAudience - the aud: field the IdToken should includeoptions - list of Credential specific options for the token. For example, an IDToken for a
ComputeEngineCredential could have the full formatted claims returned if
IdTokenProvider.Option.FORMAT_FULL) is provided as a list option. Valid option values are:
IOException - if the attempt to get an IdToken failedpublic static String getMetadataServerUrl(com.google.auth.oauth2.DefaultCredentialsProvider provider)
public static String getMetadataServerUrl()
public static String getTokenServerEncodedUrl(com.google.auth.oauth2.DefaultCredentialsProvider provider)
public static String getTokenServerEncodedUrl()
public static String getUniverseDomainUrl()
public static String getServiceAccountsUrl()
public static String getIdentityDocumentUrl()
public int hashCode()
hashCode in class GoogleCredentialsprotected com.google.common.base.MoreObjects.ToStringHelper toStringHelper()
GoogleCredentialstoStringHelper in class GoogleCredentialspublic boolean equals(Object obj)
equals in class GoogleCredentialspublic ComputeEngineCredentials.Builder toBuilder()
toBuilder in class GoogleCredentialspublic static ComputeEngineCredentials.Builder newBuilder()
public String getAccount()
getAccount in interface ServiceAccountSignerRuntimeException - if the default service account cannot be readpublic byte[] sign(byte[] toSign)
The Compute Engine's project must enable the Identity and Access Management (IAM) API and the instance's service account must have the iam.serviceAccounts.signBlob permission.
sign in interface ServiceAccountSignertoSign - bytes to signSigningException - if the attempt to sign the provided bytes failedCopyright © 2025 Google. All rights reserved.