Android Kotlin mini-project where i applied Clean architecture to implement Firebase Google Sign-In.
- Connect Android studio to Firebase app in Firebase console: this can be done after selecting Tools -> firebase -> Authentication -> Authenticate using Google
-
Set the SHA certificate fingerprints key in Firebase console: this key you can get it from
signingReportgradle task in the android studio project -
After connection is successful, add the
google-services.jsonfile to the project -
Add Gradle dependencies:
implementation("com.google.firebase:firebase-auth-ktx:22.3.0") implementation("com.google.android.gms:play-services-auth:20.7.0") -
Have an instance of
SignInClient:private val googleSignInClient by lazy { Identity.getSignInClient(applicationContext) } -
Prepare the SingIn intent:
SignInClient.beginSignIn( BeginSignInRequest.Builder() .setGoogleIdTokenRequestOptions( GoogleIdTokenRequestOptions.builder() .setSupported(true) .setFilterByAuthorizedAccounts(false) .setServerClientId(context.getString(R.string.web_client_id)) .build() ) .setAutoSelectEnabled(true) .build() )where the
web_client_idis set under your firebase project -> Authentication -> Sign-in method -> google -> Web SDK configuration -
Once we receive intent as response, we actually signin:
val credential = SignInClient?.getSignInCredentialFromIntent(intent) val googleIdToken = credential?.googleIdToken val googleCredentials = GoogleAuthProvider.getCredential(googleIdToken, null) ... val user = auth.signInWithCredential(googleCredentials).await().user ...
No user should be connected using google account, bear in mind that at least you should have a connected google account in the device.



