DEV Community

Papon Ahasan
Papon Ahasan

Posted on • Edited on

Firebase Authentication

In your module (app-level) Gradle file (/build.gradle), add the dependency for the Firebase Authentication Android library.

dependencies {
    // Import the BoM for the Firebase platform
    implementation platform('com.google.firebase:firebase-bom:31.2.0')

    implementation 'com.google.firebase:firebase-auth-ktx'
}
Enter fullscreen mode Exit fullscreen mode

Authentication Services

  • Sign-in providers : Firebase Auth by adding your first sign-in method

Image description

Image description

  • Templates

Image description

Sign in with Google

  • In your module (app-level) Gradle file. add the dependency for the Firebase Authentication Android library.
dependencies {
//Google Play services library and specify its version
    implementation 'com.google.android.gms:play-services-auth:20.4.1'
}
Enter fullscreen mode Exit fullscreen mode
  • XML Desing
    <com.google.android.gms.common.SignInButton
        android:id="@+id/signInBtn"
        android:layout_width="match_parent"
        android:layout_margin="16dp"
        android:layout_gravity="center"
        android:layout_height="wrap_content"/>
Enter fullscreen mode Exit fullscreen mode
        // [START config_signin]Configure Google Sign In
      val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.web_client_id))
            .requestEmail()
            .build()
Enter fullscreen mode Exit fullscreen mode

You must pass your "server" client ID to the Credentials page. To find the OAuth 2.0 client ID: The Web application type client ID is your backend server's OAuth 2.0 client ID

    private lateinit var googleSignInClient: GoogleSignInClient
    private const val RC_SIGN_IN = 9001
    googleSignInClient = GoogleSignIn.getClient(this, gso)

   // [START signin]
    private fun signIn() {
        val signInIntent = googleSignInClient.signInIntent
        startActivityForResult(signInIntent, RC_SIGN_IN)
    }
Enter fullscreen mode Exit fullscreen mode

onViewCreated
onStart
updateUI
then click
signIn
onActivityResult
firebaseAuthWithGoogle
updateUI

onViewCreated
onStart
updateUI

Image description

Email and Password

Sign in with Facebook

Phone Number

Top comments (0)