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'
}
Authentication Services
- Sign-in providers : Firebase Auth by adding your first sign-in method
- Templates
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'
}
- 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"/>
// [START config_signin]Configure Google Sign In
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.web_client_id))
.requestEmail()
.build()
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)
}
onViewCreated
onStart
updateUI
then click
signIn
onActivityResult
firebaseAuthWithGoogle
updateUI
onViewCreated
onStart
updateUI
Top comments (0)