Class DefaultCredentialsProvider

java.lang.Object
com.google.auth.oauth2.DefaultCredentialsProvider

class DefaultCredentialsProvider extends Object
Provides the Application Default Credential from the environment.

An instance represents the per-process state used to get and cache the credential and allows overriding the state and environment for testing purposes.

  • Field Details

  • Constructor Details

    • DefaultCredentialsProvider

      DefaultCredentialsProvider()
  • Method Details

    • getDefaultCredentials

      final GoogleCredentials getDefaultCredentials(HttpTransportFactory transportFactory) throws IOException
      Returns the Application Default Credentials.

      Returns the Application Default Credentials which are used to identify and authorize the whole application. The following are searched (in order) to find the Application Default Credentials:

      1. Credentials file pointed to by the GOOGLE_APPLICATION_CREDENTIALS environment variable
      2. Credentials provided by the Google Cloud SDK gcloud auth application-default login command
      3. Google App Engine built-in credentials
      4. Google Cloud Shell built-in credentials
      5. Google Compute Engine built-in credentials
      Parameters:
      transportFactory - HTTP transport factory, creates the transport used to get access tokens.
      Returns:
      the credentials instance.
      Throws:
      IOException - if the credentials cannot be created in the current environment.
    • getDefaultCredentialsUnsynchronized

      private final GoogleCredentials getDefaultCredentialsUnsynchronized(HttpTransportFactory transportFactory) throws IOException
      Throws:
      IOException
    • getWellKnownCredentialsFile

      private final File getWellKnownCredentialsFile()
    • warnAboutProblematicCredentials

      private void warnAboutProblematicCredentials(GoogleCredentials credentials)
    • runningOnAppEngine

      private boolean runningOnAppEngine()
    • tryGetCloudShellCredentials

      private GoogleCredentials tryGetCloudShellCredentials()
    • tryGetAppEngineCredential

      private GoogleCredentials tryGetAppEngineCredential() throws IOException
      Throws:
      IOException
    • tryGetComputeCredentials

      private final GoogleCredentials tryGetComputeCredentials(HttpTransportFactory transportFactory)
    • skipAppEngineCredentialsCheck

      private boolean skipAppEngineCredentialsCheck()
    • isOnGAEStandard7

      protected boolean isOnGAEStandard7()
    • getOsName

      String getOsName()
    • forName

      Class<?> forName(String className) throws ClassNotFoundException
      Throws:
      ClassNotFoundException
    • getEnv

      String getEnv(String name)
    • getProperty

      String getProperty(String property, String def)
    • isFile

      boolean isFile(File file)
    • readStream

      InputStream readStream(File file) throws FileNotFoundException
      Throws:
      FileNotFoundException