Class CredentialModule


  • @Module
    public abstract class CredentialModule
    extends java.lang.Object
    Dagger module that provides all GoogleCredentials used in the application.
    • Constructor Detail

      • CredentialModule

        public CredentialModule()
    • Method Detail

      • provideDefaultCredential

        @DefaultCredential
        @Provides
        @Singleton
        public static GoogleCredentialsBundle provideDefaultCredential​(@Config("defaultCredentialOauthScopes")
                                                                       com.google.common.collect.ImmutableList<java.lang.String> requiredScopes)
        Provides the default GoogleCredentialsBundle from the Google Cloud runtime.

        The credential returned depends on the runtime environment:

        • On AppEngine, returns the service account credential for PROJECT_ID@appspot.gserviceaccount.com
        • On Compute Engine, returns the service account credential for PROJECT_NUMBER-compute@developer.gserviceaccount.com
        • On end user host, this returns the credential downloaded by gcloud. Please refer to Cloud SDK documentation for details.
      • provideGSuiteDriveCredential

        @GSuiteDriveCredential
        @Provides
        @Singleton
        public static com.google.api.client.googleapis.auth.oauth2.GoogleCredential provideGSuiteDriveCredential​(@Config("defaultCredentialOauthScopes")
                                                                                                                 com.google.common.collect.ImmutableList<java.lang.String> requiredScopes)
        Provides the default GoogleCredential from the Google Cloud runtime for G Suite Drive API. TODO(b/138195359): Deprecate this credential once we figure out how to use GoogleCredentials for G Suite Drive API.
      • provideJsonCredential

        @JsonCredential
        @Provides
        @Singleton
        public static GoogleCredentialsBundle provideJsonCredential​(@Config("defaultCredentialOauthScopes")
                                                                    com.google.common.collect.ImmutableList<java.lang.String> requiredScopes,
                                                                    @Key("jsonCredential")
                                                                    java.lang.String jsonCredential)
        Provides a GoogleCredentialsBundle from the service account's JSON key file.

        On App Engine, a thread created using Java's built-in API needs this credential when it calls App Engine API. The Google Sheets API also needs this credential.

      • provideDelegatedCredential

        @DelegatedCredential
        @Provides
        @Singleton
        public static GoogleCredentialsBundle provideDelegatedCredential​(@Config("delegatedCredentialOauthScopes")
                                                                         com.google.common.collect.ImmutableList<java.lang.String> requiredScopes,
                                                                         @JsonCredential
                                                                         GoogleCredentialsBundle credentialsBundle,
                                                                         @Config("gSuiteAdminAccountEmailAddress")
                                                                         java.lang.String gSuiteAdminAccountEmailAddress)
        Provides a GoogleCredentialsBundle with delegated admin access for a G Suite domain.

        The G Suite domain must grant delegated admin access to the registry service account with all scopes in requiredScopes, including ones not related to G Suite.