You can use Google Play Games services to sign players in to an Android game
built on Firebase. To use Google Play Games services sign-in with Firebase,
first sign the player in with Google Play Games, and request an OAuth 2.0 auth
code when you do so. Then, pass the auth code to PlayGamesAuthProvider 
to
generate a Firebase credential, which you can use to authenticate with Firebase.
Before you begin
Set up your Android project
-  If you haven't already, add Firebase to your Android project . 
-  In your module (app-level) Gradle file (usually <project>/<app-module>/build.gradle.ktsor<project>/<app-module>/build.gradle), add the dependency for the Firebase Authentication library for Android. We recommend using the Firebase Android BoM to control library versioning.Also, as part of setting up Firebase Authentication , you need to add the Google Play services SDK to your app. dependencies { // Import the BoM for the Firebase platform implementation ( platform ( "com.google.firebase:firebase-bom:34.4.0" )) // Add the dependency for the Firebase Authentication library // When using the BoM , you don't specify versions in Firebase library dependencies implementation ( "com.google.firebase:firebase-auth" ) 
 // Also add the dependency for the Google Play services library and specify its version implementation ( "com.google.android.gms:play-services-auth:21.4.0" ) }By using the Firebase Android BoM , your app will always use compatible versions of Firebase Android libraries. (Alternative) Add Firebase library dependencies without using the BoM If you choose not to use the Firebase BoM , you must specify each Firebase library version in its dependency line. Note that if you use multiple Firebase libraries in your app, we strongly recommend using the BoM to manage library versions, which ensures that all versions are compatible. dependencies { // Add the dependency for the Firebase Authentication library // When NOT using the BoM , you must specify versions in Firebase library dependencies implementation ( "com.google.firebase:firebase-auth:24.0.1" ) 
 // Also add the dependency for the Google Play services library and specify its version implementation ( "com.google.android.gms:play-services-auth:21.4.0" ) }
Set up your Firebase project
-  Set your game's SHA-1 fingerprint from the Settings page of the Firebase console. You can get the SHA hash of your signing certificate with the gradle signingReportcommand:./gradlew signingReport 
-  Enable Google Play Games as a sign-in provider: -  Find your project's web server client ID and client secret. The web server client ID identifies your Firebase project to the Google Play auth servers. To find these values: - Open your Firebase project in the Google APIs console credentials page.
- In the OAuth 2.0 client IDssection, open the Web client (auto created by Google Service)details page. This page lists your web server client ID and secret.
 
-  Then, in the Firebase console , open the Authenticationsection. 
-  On the Sign in methodtab, enable the Play Gamessign-in provider. You will need to specify your project's web server client ID and client secret, which you got from the APIs console. 
 
-  
Configure Play Games services with your Firebase app information
-  In the Google Play Console , open your Google Play app or create one. 
-  In the Grow section, click Play Games services > Setup & Management > Configuration. 
-  Click Yes, my game already uses Google APIs, select your Firebase project from the list, and then click Use. 
-  On the Play Games services configuration page, click Add Credential. - Select the Game servertype.
- In the OAuth clientfield, select your project's web client ID. Be sure this is the same client ID you specified when you enabled Play Games sign-in.
- Save your changes.
 
-  Still on the Play Games services configuration page, click Add Credentialagain. - Select the Androidtype.
- In the OAuth clientfield, select your project's Android client ID. (If you don't see your Android client ID, be sure you set your game's SHA-1 fingerprint in the Firebase console.)
- Save your changes.
 
-  On the Testerspage, add the email addresses of any users who need to be able to sign in to your game before you release it on the Play Store . 
Integrate Play Games sign-in into your game
First, integrate Play Games sign-in into your app. See Sign in to Android Games for complete instructions.
In your integration, when you build the GoogleSignInOptions 
object, use the DEFAULT_GAMES_SIGN_IN 
configuration and call requestServerAuthCode 
:
Kotlin
val gso = GoogleSignInOptions . Builder ( GoogleSignInOptions . DEFAULT_GAMES_SIGN_IN ) . requestServerAuthCode ( getString ( R . string . default_web_client_id )) . build ()
Java
GoogleSignInOptions gso = new GoogleSignInOptions . Builder ( GoogleSignInOptions . DEFAULT_GAMES_SIGN_IN ) . requestServerAuthCode ( getString ( R . string . default_web_client_id )) . build ();
You must pass your web server client ID to the requestServerAuthCode 
method.
This is the ID that you provided when you enabled Play Games sign-in in the Firebase 
console.
Authenticate with Firebase
After you add Play Games sign-in to your app, you need to set up Firebase to use the Google account credentials that you get when a player signs in successfully with Play Games.
- First, in your sign-in activity's onCreatemethod, get the shared instance of theFirebaseAuthobject:
Kotlin
private lateinit var auth : FirebaseAuth // ... // Initialize Firebase Auth auth = Firebase . auth . kt

