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.Builder |
OAuth2Credentials.CredentialsChangedListenerServiceAccountSigner.SigningExceptionIdTokenProvider.Option| 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.
|
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) |
Collection<String> |
getScopes() |
static String |
getServiceAccountsUrl() |
static String |
getTokenServerEncodedUrl() |
static String |
getTokenServerEncodedUrl(com.google.auth.oauth2.DefaultCredentialsProvider provider) |
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() |
String |
toString() |
create, createDelegated, createScoped, createScopedRequired, fromStream, fromStream, getApplicationDefault, getApplicationDefaultaddChangeListener, getAccessToken, getAdditionalHeaders, getAuthenticationType, getFromServiceLoader, getRequestMetadata, getRequestMetadata, getRequestMetadataInternal, hasRequestMetadata, hasRequestMetadataOnly, newInstance, refresh, refreshIfExpired, removeChangeListenerblockingGetToCallback, getRequestMetadatapublic GoogleCredentials createScoped(Collection<String> newScopes)
createScoped in class GoogleCredentialsnewScopes - Collection of scopes to request.public static ComputeEngineCredentials create()
public final Collection<String> getScopes()
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 getServiceAccountsUrl()
public static String getIdentityDocumentUrl()
public int hashCode()
hashCode in class OAuth2Credentialspublic String toString()
toString in class OAuth2Credentialspublic boolean equals(Object obj)
equals in class OAuth2Credentialspublic 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 © 2021 Google. All rights reserved.