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.CredentialsChangedListener
ServiceAccountSigner.SigningException
IdTokenProvider.Option
quotaProjectId
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.
|
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, createWithCustomRetryStrategy, createWithQuotaProject, fromStream, fromStream, getAdditionalHeaders, getApplicationDefault, getApplicationDefault, getQuotaProjectId
addChangeListener, getAccessToken, getAuthenticationType, getFromServiceLoader, getRequestMetadata, getRequestMetadata, getRequestMetadataInternal, hasRequestMetadata, hasRequestMetadataOnly, newInstance, refresh, refreshIfExpired, removeChangeListener
blockingGetToCallback, getRequestMetadata
public GoogleCredentials createScoped(Collection<String> newScopes)
createScoped
in class GoogleCredentials
newScopes
- Collection of scopes to request.public GoogleCredentials createScoped(Collection<String> newScopes, Collection<String> newDefaultScopes)
createScoped
in class GoogleCredentials
newScopes
- Collection of scopes to request.newDefaultScopes
- Collection of default scopes to request.public static ComputeEngineCredentials create()
public final Collection<String> getScopes()
public AccessToken refreshAccessToken() throws IOException
refreshAccessToken
in class OAuth2Credentials
IOException
public IdToken idTokenWithAudience(String targetAudience, List<IdTokenProvider.Option> options) throws IOException
idTokenWithAudience
in interface IdTokenProvider
targetAudience
- 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 OAuth2Credentials
public String toString()
toString
in class OAuth2Credentials
public boolean equals(Object obj)
equals
in class OAuth2Credentials
public ComputeEngineCredentials.Builder toBuilder()
toBuilder
in class GoogleCredentials
public static ComputeEngineCredentials.Builder newBuilder()
public String getAccount()
getAccount
in interface ServiceAccountSigner
RuntimeException
- 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 ServiceAccountSigner
toSign
- bytes to signSigningException
- if the attempt to sign the provided bytes failedCopyright © 2023 Google. All rights reserved.