Send feedback
  
   
 
  
    
      Class ComputeEngineCredentials (1.3.0)
    
    
       
    
    
      
      Stay organized with collections
     
    
      
      Save and categorize content based on your preferences.
     
    
  
      
     
  
  
   
  
    
  
  
    
    
    
  Version 1.3.0keyboard_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.
 
  
  
  
  Methods
   
   
  create() 
  
    
public   static   ComputeEngineCredentials   create ()  
   
  Create a new ComputeEngineCredentials instance with default behavior.
 
  Returns 
  
   
  createScoped(Collection<String> newScopes) 
  
    
public   GoogleCredentials   createScoped ( Collection<String>   newScopes )  
   
  Clones the compute engine account with the specified scopes.
 
  Parameter 
  
  Returns 
  
  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.
 
  Parameters 
  
  Returns 
  
  Overrides 
  
   
  equals(Object obj) 
  
    
public   boolean   equals ( Object   obj )  
   
  Parameter 
  
  Returns 
  
  Overrides 
  
   
  getAccount() 
  
    
public   String   getAccount ()  
   
  Returns the email address associated with the GCE default service account.
 
  Returns 
  
   
  getIdentityDocumentUrl() 
  
    
public   static   String   getIdentityDocumentUrl ()  
   
  Returns 
  
   
  
  
    
public   static   String   getMetadataServerUrl ()  
   
  Returns 
  
   
  
  
    
public   static   String   getMetadataServerUrl ( DefaultCredentialsProvider   provider )  
   
  Parameter 
  
    
      
        Name  
        Description  
       
      
        provider  
        com.google.auth.oauth2.DefaultCredentialsProvider  
       
     
  
  Returns 
  
   
  getScopes() 
  
    
public   final   Collection<String>   getScopes ()  
   
  Returns 
  
   
  getServiceAccountsUrl() 
  
    
public   static   String   getServiceAccountsUrl ()  
   
  Returns 
  
   
  getTokenServerEncodedUrl() 
  
    
public   static   String   getTokenServerEncodedUrl ()  
   
  Returns 
  
   
  getTokenServerEncodedUrl(DefaultCredentialsProvider provider) 
  
    
public   static   String   getTokenServerEncodedUrl ( DefaultCredentialsProvider   provider )  
   
  Parameter 
  
    
      
        Name  
        Description  
       
      
        provider  
        com.google.auth.oauth2.DefaultCredentialsProvider  
       
     
  
  Returns 
  
   
  hashCode() 
  
  Returns 
  
  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
 
       
     
  
   
  newBuilder() 
  
    
public   static   ComputeEngineCredentials . Builder   newBuilder ()  
   
  Returns 
  
   
  refreshAccessToken() 
  
    
public   AccessToken   refreshAccessToken ()  
   
  Refresh the access token by getting it from the GCE metadata server
 
  Returns 
  
  Overrides 
  
  Exceptions 
  
   
  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.
 
  Parameter 
  
    
      
        Name  
        Description  
       
      
        toSign  
        byte []bytes to sign
 
       
     
  
  Returns 
  
    
      
        Type  
        Description  
       
      
        byte [] 
        signed bytes
 
       
     
  
   
  toBuilder() 
  
    
public   ComputeEngineCredentials . Builder   toBuilder ()  
   
  Returns 
  
  Overrides 
  
   
  toString() 
  
  Returns 
  
  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 2025-10-30 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 2025-10-30 UTC."],[],[]]