DEV Community

loizenai
loizenai

Posted on

Kotlin Firebase Authentication – Google Sign In | Android

https://grokonez.com/android/kotlin-firebase-authentication-google-sign-in-android

Kotlin Firebase Authentication – Google Sign In | Android

In previous post, we had built a simple register/login Android App using Firebase Email & Password authentication. Now we can let users authenticate with Firebase using Google Accounts by integrating Google Sign In into Kotin Android App.

Related articles:

I. Way to do

1. Add Firebase to Android App

  • Read Kotlin Firebase Authentication – How to Sign Up, Sign In, Sign Out, Verify Email | Android and follow steps to enable and implement Firebase Auth in your Android App.

  • Add dependency: build.gradle (App-level):

    
    dependencies {
    // ...
    implementation 'com.google.android.gms:play-services-auth:11.0.4'
    }
    

    2. Enable Firebase Auth for Google Account

    Go to Your Firebase Project Console -> Authentication -> SIGN-IN METHOD -> Enable Google:
    firebase-google-signin-enable-console

    3. Steps to authenticate with Firebase

    3.1 Integrate Google Sign In into App

    1- Add the Google Sign-In button:

    
    
    

    2- Configure Google Sign In object to request the user data:
    When you configure the GoogleSignInOptions object, call requestIdToken:

    
    override fun onCreate(savedInstanceState: Bundle?) {
    // ...
    
    val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(WEB_CLIENT_ID)
            .requestEmail()
            .build()
    }

    With WEB_CLIENT_ID from Credentials page in the API Console -> OAuth 2.0 client IDs (Type Web Application).

3- Configure GoogleApiClient object with access to the Google Sign In API and the options above:

More at:

https://grokonez.com/android/kotlin-firebase-authentication-google-sign-in-android

Kotlin Firebase Authentication – Google Sign In | Android

Top comments (0)