Send feedback
Class ComputeEngineCredentials (1.20.0)
Stay organized with collections
Save and categorize content based on your preferences.
Version 1.20.0 keyboard_arrow_down
public class ComputeEngineCredentials extends GoogleCredentials implements ServiceAccountSigner , IdTokenProvider
OAuth2 credentials representing the built-in service account for a Google Compute Engine VM.
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.
Static Methods
create()
public static ComputeEngineCredentials create ()
Create a new ComputeEngineCredentials instance with default behavior.
getIdentityDocumentUrl()
public static String getIdentityDocumentUrl ()
Returns
Type
Description
String
public static String getMetadataServerUrl ()
Returns
Type
Description
String
public static String getMetadataServerUrl ( DefaultCredentialsProvider provider )
Parameter
Name
Description
provider
com.google.auth.oauth2.DefaultCredentialsProvider
Returns
Type
Description
String
getServiceAccountsUrl()
public static String getServiceAccountsUrl ()
Returns
Type
Description
String
getTokenServerEncodedUrl()
public static String getTokenServerEncodedUrl ()
Returns
Type
Description
String
getTokenServerEncodedUrl(DefaultCredentialsProvider provider)
public static String getTokenServerEncodedUrl ( DefaultCredentialsProvider provider )
Parameter
Name
Description
provider
com.google.auth.oauth2.DefaultCredentialsProvider
Returns
Type
Description
String
newBuilder()
public static ComputeEngineCredentials . Builder newBuilder ()
Methods
createScoped(Collection<String> newScopes)
public GoogleCredentials createScoped ( Collection<String> newScopes )
Clones the compute engine account with the specified scopes.
Overrides
createScoped(Collection<String> newScopes, Collection<String> newDefaultScopes)
public GoogleCredentials createScoped ( Collection<String> newScopes , Collection<String> newDefaultScopes )
Clones the compute engine account with the specified scopes.
Overrides
equals(Object obj)
public boolean equals ( Object obj )
Parameter
Name
Description
obj
Object
Overrides
getAccount()
public String getAccount ()
Returns the email address associated with the GCE default service account.
Returns
Type
Description
String
getScopes()
public final Collection<String> getScopes ()
hashCode()
Returns
Type
Description
int
Overrides
idTokenWithAudience(String targetAudience, List<IdTokenProvider.Option> options)
public IdToken idTokenWithAudience ( String targetAudience , List<IdTokenProvider . Option > options )
Returns a Google ID Token from the metadata server on ComputeEngine
Parameters
Name
Description
targetAudience
String
the aud: field the IdToken should include
options
List <Option >
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:
IdTokenProvider.Option.FORMAT_FULL
IdTokenProvider.Option.LICENSES_TRUE
If no options are set, the defaults are "&format=standard&licenses=false"
Returns
Type
Description
IdToken
IdToken object which includes the raw id_token, JsonWebSignature
Exceptions
Type
Description
IOException
if the attempt to get an IdToken failed
refreshAccessToken()
public AccessToken refreshAccessToken ()
Refresh the access token by getting it from the GCE metadata server
Overrides
sign(byte[] toSign)
public byte [] sign ( byte [] toSign )
Signs the provided bytes using the private key associated with the service account.
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.
See Also: Blob Signing
Parameter
Name
Description
toSign
byte []
bytes to sign
Returns
Type
Description
byte []
signed bytes
toBuilder()
public ComputeEngineCredentials . Builder toBuilder ()
Overrides
toString()
Returns
Type
Description
String
Overrides
Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-12-19 UTC.
Need to tell us more?
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-19 UTC."],[],[]]