94

So I'm Stuck on this frustrating issue. I am quite new to Google Auth on Firebase but I done everything the firebase docs instructed in how to integrate the Google SignIn Auth, yet I'm still receiving this weird Error in the console consisted of two parts:

12-03 11:07:40.090 2574-3478/com.google.android.gms E/TokenRequestor: You have wrong OAuth2 related configurations, please check. Detailed error: UNREGISTERED_ON_API_CONSOLE

and also

Google sign in failed com.google.android.gms.common.api.ApiException: 10:

Before Anyone attempts to point out similar questions that have previously been asked on stack overflow, Here's what I have done till now after seen all the available solutions and yet non has resolved the error

  • I have my SHA1 fingerprint for my project
  • I have my OAuth 2.0 client ID, both, the android client id and the web client and in the requestIdToken() I have put the web client id.
  • I did not publish my project's APK on google play store. which means I did not accidentally generate another SHA1 fingerprint.
  • I have followed step by step the Google Sign in Auth firebase docs.

here is my code snippet:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signup);
    ButterKnife.bind(this);

    String webClientId = getString(R.string.web_client_id);


    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestIdToken(webClientId)
            .build();

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);


    GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);


    googleLoginBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent signInIntent = mGoogleSignInClient.getSignInIntent();
            startActivityForResult(signInIntent, RC_SIGN_IN);
        }
    });

}



@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        // The Task returned from this call is always completed, no need to attach
        // a listener.
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);

        try{

            GoogleSignInAccount account = task.getResult(ApiException.class);
            firebaseAuthWithGoogle(account);

        } catch (ApiException e) {
            // Google Sign In failed, update UI appropriately
            Log.w(TAG, "Google sign in failed", e);
            // [START_EXCLUDE]
            Toast.makeText(this, "Gooogle Auth failed", Toast.LENGTH_LONG);
            // [END_EXCLUDE]
        }

    }
}



private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
    // [START_EXCLUDE silent]
    //showProgressDialog();
    // [END_EXCLUDE]

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        // Sign in success, update UI with the signed-in user's information
                        Log.d(TAG, "signInWithCredential:success");
                        FirebaseUser user = mAuth.getCurrentUser();
                        Toast.makeText(LoginActivity.this, "Successful Auth", Toast.LENGTH_LONG).show();
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w(TAG, "signInWithCredential:failure", task.getException());
                        Toast.makeText(LoginActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                        //updateUI(null);
                    }

                    // [START_EXCLUDE]
                    //hideProgressDialog();
                    // [END_EXCLUDE]
                }
            });
}
Hudi Ilfeld
  • 1,905
  • 2
  • 16
  • 25
  • 2
    Basically problem is in the SHA1 key put on console please regenerate it and put again properly same project – Dilip Dec 03 '17 at 14:19
  • 3
    Yes, appareantly you were a big help!! regenerating my SHA1 fingerprint resolved the issue. thanks. but still, I'm curious how come there was problem with the fingerprint if firebase generated it in the first place. and I haven't modified since then?? – Hudi Ilfeld Dec 03 '17 at 14:48
  • which solution did u follow to fix the issue – hasan_shaikh Dec 06 '19 at 06:36
  • @hasan_shaikh the accepted one – Hudi Ilfeld Dec 06 '19 at 09:10
  • It's crazy but after creating new android OAuth in google developer console app continues returning ApiException 10. Removing app and stalling new one solves this problem for me – Dmytro Batyuk Feb 05 '21 at 08:05
  • The google sign in API is outrageous. I have got the EXACT same behavior, when suddendly it will stop working in release (using SHA1 production key). Re-creating creds in google cloud console unblocks it for a few hours and then it comes back with error 10. I've never seen something so BADLY documented and so UNCONSISTANT. @DmytroBatyuk have you ever had the chance to fix your issue ? – Umar3x Jun 04 '23 at 15:51
  • @Umar3x no, I don't – Dmytro Batyuk Jun 05 '23 at 17:56

28 Answers28

117

Basically problem is in the SHA1 key put on console please regenerate it and put again properly same project.

1)As the answers, make sure that your actual signed Android apk has the same SHA1 fingerprint as what you specified in the console of your Firebase project's Android integration section (the page where you can download the google-services.json)

For more info, see: Generate SHA-1 for Flutter app

2)On top of that go to the Settings of your firebase project (gear icon right to the Overview at the top-left area. Then switch to Account Linking tab. On that tab link the Google Play to your project.

EDIT: Account Linking tab doesn't exist any more, instead :

  1. Sign in to Firebase.
  2. Click the Settings icon, then select Project settings.
  3. Click the Integrations tab.
  4. On the Google Play card, click Link.

enter image description here

Elia Weiss
  • 8,324
  • 13
  • 70
  • 110
Dilip
  • 2,622
  • 1
  • 20
  • 27
  • 3
    In my case Firebase had both the "App signing certificate" and my "Upload certificate" SHA-1 keys set. So I had two SHA-1 keys in Firebase. I deleted the one that was the same as my "Upload certificate" and only kept the "App signing certificate", this solved my problem. – jesobremonte May 21 '18 at 11:19
  • 2
    Surprisingly, i had added sha1 of release build in firebase console and it was working good if i install release build directly by moving to file manager. Once i published the same release apk on google play store , google sign in stopped working. Then by following your suggestion i went to Account Linking tab and linked the Google Play to my project then it started working. – jatin rana Jul 05 '18 at 12:26
  • 1
    I'm getting this issue after trying everything. Could be related that I moved from Ionic to Flutter? I also copied the same keystore but I think it shouldn't be a problem, right? Don't know what else to try – Dani Nov 21 '19 at 10:19
  • @dilip I am also facing the same issue. I have added the SH256 generated by play console to the firebase account. Can you please help out in this. – hasan_shaikh Dec 06 '19 at 06:34
  • Make sure you are using the correct keystore file's fingerprint in console. (for me, flutter uses one in `~/.android/debuge.keystore`) – Hritik Jan 06 '20 at 18:27
  • This particular error can happen for reasons other than SHA-1 mismatch. Not having taken enough 'Scope' specific permissions during sign-in could be another reason. – Ajmal Moochingal Apr 27 '20 at 12:07
  • 1
    Linking my project to Google Play solved a persistent and confusing issue for me. Thank you so much! – lwilber May 03 '20 at 21:07
  • Can you elaborate on option (2) I can seem to find `Account Linking` tab when clicking on the gear icon – Elia Weiss Jun 13 '20 at 07:54
32

When using App Signing by Google Play and Firebase, you need to add the SHA-1 fingerprint of the App signing certificate (found on Google Play Console/ Release Management/ App signing certificate) to the Firebase Console/ Settings/ SHA certificate fingerprints

Updated location for the SHAs: Google Play Console > Release > Setup > App integrity

Anonsage
  • 8,030
  • 5
  • 48
  • 51
Assaf S.
  • 4,676
  • 2
  • 22
  • 18
  • 3
    Thanks a lot. It saved me. I am about to panic! – Sudarshan May 16 '19 at 16:31
  • 3
    This was the third sha-1 to put in there and it finally did the trick! I first had the debug only, then i added the upload certificate one, and finally the app signing certificate and that did the trick, THANK YOU! – Kevin Jan 18 '20 at 21:44
  • @Kevin So, you ended up using adding four SHA-1 fingerprints to your Firebase console? Which client ID did you use what corresponds to the SHA-1 fingerprint? – J0nathan Lam Mar 19 '20 at 18:04
  • 1
    It turns out the upload certificate SHA-1 is the same as the release SHA-1. So, I've added three SHA-1 to my firebase console (release, debug, App signing certificate) Which client ID did you use? Because I'm still getting the exception 10 error. – J0nathan Lam Mar 19 '20 at 18:15
  • Dude... finally found this after 20+ hours of not figuring it out, thank you. – Merthan Erdem Sep 16 '20 at 21:47
  • It seems like it's a marathon for every developer! My share was 7 hours of debugging and I wrote about the 3 SHA-1s here: https://stackoverflow.com/a/72440651 – Aidin May 30 '22 at 22:43
18

In My case, There is no problem with SHA-1

I have done GoogleAuth using Firebase.

I forgot to add implementation 'com.firebaseui:firebase-ui-auth:4.3.1'

And I put my own key instead of R.string.default_web_client_id, So that was the problem. I added above dependency and replace R.string.default_web_client_id with my own key.

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(getString(R.string.default_web_client_id))
                .requestEmail()
                .build();

UPDATE : 18-Dec-2020

We can also use without requestIdToken like below. For this you must have to add your SHA1 to google console.

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .build();
Chirag Savsani
  • 6,020
  • 4
  • 38
  • 74
  • Thank you so much, this worked for me, why isn't this documented anywhere? All the official docs I was reading from Google never even mentioned importing firebase-ui-auth or R.string.default_web_client_id. – BananyaDev Apr 17 '19 at 01:03
  • Don't know but I faced this issue, and spend too much time on this issue. I solved the issue on my own. – Chirag Savsani Apr 17 '19 at 05:22
15

I was facing the same issue, After checking around for a solution, from regenerating the finger print to linking the app on firebase to the Google play console and publishing the signed apk, the issue was actually because I was using the release SHA-1 on the firebase console.

  • If you are still on debug mode, use the debug.keystore SHA1
  • Only use the release SHA1 if you are on production mode

https://developer.android.com/studio/publish/app-signing.html

Min2
  • 10,751
  • 2
  • 19
  • 22
Gomez NL
  • 912
  • 9
  • 12
9

My solution was a little different,

After hours of trying various things. I found my solution:

Using the steps listed here: https://stackoverflow.com/a/34223470/10575896

  1. Open Android Studio
  2. Open your Project
  3. Click on Gradle (From Right Side Panel, you will see Gradle Bar)
  4. Click on Refresh (Click on Refresh from Gradle Bar, you will see List Gradle scripts of your Project)
  5. Click on Your Project (Your Project Name form List (root))
  6. Click on Tasks
  7. Click on Android
  8. Double Click on signingReport (You will get SHA1 and MD5 in Run Bar(Sometimes it will be in Gradle Console))

The console will print out the SHA keys for both debug and release. I had added the debug keys to firebase sometime in the past, but I had not added the release keys.

I simply added the SHA1 and SHA256 keys to firebase, and I was good to go.

Airborne Eagle
  • 373
  • 5
  • 11
  • Specifically For React Native project https://app.box.com/s/vf9ez8h8u9ran38ltk5hyupmuwq8bw3l – Chirag Purohit Apr 08 '20 at 17:46
  • It's 2022 and the SHA1 that you want is no longer in gradle. It's actually in Play Console itself. See https://stackoverflow.com/a/72440651 – Aidin May 30 '22 at 22:44
5

If you have all configuration valid in firebase like SHA-1 and you have imported right google-services.json file still you are getting error then add the support email in firebase console

You have to add support email in fire base console Go to Project-> Setting -> General -> Public setting add Support Email

  • 2
    +1 Don't know why Support email should affect any config but it does and setting the email solved `com.google.android.gms.common.api.ApiException: 12500: ` SIGN_IN_FAILED error – John Jun 05 '19 at 12:04
  • this is the one answer. THANK YOU. – Lexy Feito Jun 05 '19 at 21:33
5

It's 2022 and I spent 7 hours debugging this! I am not a native Android developer so I didn't know what's what until now.

Here is how I made it to work.

1) Make sure you have different build numbers between dev and prod!

There are 3 different builds/app in the world that you are playing with:

  1. The one in Google Play Store that you can install. It has a build number associated with it, both in the Play Store and in the App -> tap and hold -> info.
  2. The one in Android Studio build that has release build flavor
  3. The one in Android Studio build that has debug build flavor

enter image description here

The debug one is the one you can attach the debugger (the bug icon!) and release is the one that you cannot.

Whatever you do, make sure these are different or you will pull your hair why it works here and not there!

Android: Tag > Build > Release > then immediately version bump

I am coming from a background that we tag and version right before the release. (e.g. backend) Here, if you do so, it messes everything up! So you should tag, then release, then version bump immediately!

Ideally, the Play store should be 1.1.7, the release one should be 1.1.8 (yes, one version ahead as it's the one you are going to publish), and the debug one should be 1.1.8-debug.

If you don't do so, and they are the same, Android OS is going to cache the packages/APKs. So even if you go and install the app from Play Store, it might use an Android Studio version that it has in cache, with its own certificate! (That took me 4 hours of not knowing why installing the same app from Play Store on two phones, yielded different behaviors -- one was using the cached APK from Android Studio USB builds.)

2) You need at least 4 different Oauth Client ID Keys from GCP!

At this point, you should be aware of the crazy system that you should create a "Web" OAuth Client ID for Android, and also a dummy Android one! See this.

Yes, you need one "Web" key, and one "Android" key to have the GoogleSignIn work. You should use the "Web" one almost everywhere (except for doing server-side token validation, where you verify the audience/issuer of the JWT). Regardless, without the unused dummy "Android" one, it's not gonna work.

However, the part that I didn't know was that you need 3 Android + 1 Web!

When you create an Android OAuth Client ID, it asks for a SHA-1.

enter image description here

And each of those 3 apps has its own certificates, a.k.a SHA-1s.

How to get 3 SHA-1s?

For 2 and 3 (release and debug of Android Studio) you can get them from gradle via this solution.

enter image description here

For the Play Store one, you have to go to Play Console > App Integrity > App Signing and get the "App signing" certificate from there. (The upload one should match your release one most likely.)

enter image description here

Now, go ahead and create these 3 Android Ouath Client Ids + 1 for Web and hopefully Google SignIn will work everywhere!

enter image description here

Aidin
  • 25,146
  • 8
  • 76
  • 67
3

i was dealing with this problem for 2 days ! the problem was the clientId i used, was android type while i had to use web Aplication type Clientid . please consider this if you have the same problem ;)

ParSa
  • 1,118
  • 1
  • 13
  • 17
3
  1. Make you use .requestIdToken(getString(R.string.default_web_client_id)) when you Build GoogleSignInOptions:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(getString(R.string.default_web_client_id))
                .requestEmail()
                .build();
  1. Add your debug.keystore's SHA1 and SHA256 fingerprint to your Firebase project with the following steps:
  2. Obtain the debug.keystore's fingerprints: Linux/Mac - keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore, Windows - keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore
  3. Add these fingerprint's to your Firebases project's Android app section: https://support.google.com/firebase/answer/9137403?hl=en
Csaba Toth
  • 10,021
  • 5
  • 75
  • 121
2

I had problems with each answer, so here is the solution that worked for me:

First, add Firebase to your project:

Go to Firebase web site -> Add Project -> Once when you create new project go to Add App and add your Android app

Take care to add the exact package name and debug SHA-1 key.

You can generate debug SHA-1 key doing the following in Android Studio:

On the right side open Gradle panel -> go to Tasks -> android -> run signingReport

Your SHA-1 key will be shown in Run window

Once when you register the app, download the config file. In the config .json file you can find your client_id : client -> oauth_client -> client_id

Take care there are two client_ids. The one with "client_type": 3 worked for me with the following code:

private fun requestSignIn(context: Context) {

    GoogleSignIn.getLastSignedInAccount(context)?.also { account ->
        onSignedIn(account)
        return
    }

    val signInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestScopes(Scope("https://www.googleapis.com/auth/spreadsheets"))
        .requestEmail()
        .requestIdToken("client_id_goes_here")
        .build()
    val client = GoogleSignIn.getClient(context, signInOptions)

    startActivityForResult(client.signInIntent, REQUEST_SIGN_IN)
}

Then in the onActivityResult:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)

    if (requestCode == REQUEST_SIGN_IN) {
         if( resultCode == RESULT_OK) {
            GoogleSignIn.getSignedInAccountFromIntent(data)
                .addOnSuccessListener { account ->
                    onSignedIn(account)
                }
                .addOnFailureListener { e ->
                    Log.d("Fail", "Fail")
                }
          }
    }
}

In onSignedIn you should do the google sheet api call

Mladen Rakonjac
  • 9,562
  • 7
  • 42
  • 55
2

After adding the SHA1 and SHA256 app signing certificates it still didn't work. Once I added the SHA1 App upload certificate it worked :)

Gareth Beall
  • 293
  • 3
  • 11
2

Yo guys, make sure that you have installed google play services in android studio SDK Manager. After I did it, rebuild unity project — all works fine. enter image description here

2

I have faced the same error and I solved it by fixing the value of WEB_CLIENT_ID You can check the value at: Authentication -> Sign-in Method -> Provider (ex: Google) -> Web SDK Configuration -> Web Client ID

fahrizal89
  • 598
  • 5
  • 13
1

I am not sure if this is the cause, but we might need to use the Web Client ID in the Android App before publishing it, read the following article,

https://android-developers.googleblog.com/2016/03/registering-oauth-clients-for-google.html

Ashwin Balani
  • 745
  • 7
  • 19
1

After adding the SHA1 and SHA256 app signing certificates it works.

Darotudeen
  • 1,914
  • 4
  • 21
  • 36
0

In my case to work on the emulator, I followed the steps https://stackoverflow.com/a/46767856/6800637, and in addition to putting in https://console.firebase.google.com projectName/ settings / general, my signature key sha1 and sha256 I also put the key sha1 from [debug.keystore] which is shown when you follow the steps mentioned above

AllanRibas
  • 678
  • 5
  • 14
0

This status code means that you are providing unknown server client id.

So I was able to resolve this issue by changing the OAuth Client ID at Android client:

googleSignInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken("web application client id")
            .requestEmail()
            .build()

In https://console.developers.google.com/apis/credentials in your project you might need to generate: OAuth client ID -> Web Application and use this web application client id in your Android app.

enter image description here

Min2
  • 10,751
  • 2
  • 19
  • 22
0

I had this problem recently when trying to use google sign in using Firebase. I could fix it by updating requestIdToken in GoogleSignInOptions to the one provided as client_id in google-services.json file.

eracube
  • 2,484
  • 2
  • 15
  • 18
0

These are all great answers, in case anyone else is trying to have multiple firebase projects for one app, i.e. development and production the trick is when you want to test production, you'll need to upload the APK to Google Play if you use Google Play to manage the signing of your app. I used the internal testing track, and then it started working.

You cannot just install the APK on your device with your debug keys, because it does not match the production keys in Firebase.

Another side note - as others have mentioned - for some reason you need to use the "web" OAuth client ID, NOT the Android OAuth client. This is a really confusing thing for Google to do.

slothstronaut
  • 921
  • 1
  • 13
  • 15
0

Although, the tutorial and the configuration page suggests to get the package name from the manifest file, it seems it is checked against the "applicationId" in the "app/build.gradle" file.

There are two places to set the package name I've found so far:

app/src/main/AndroidManifest.xml

app/build.gradle android.defaultConfig.applicationId

In my case those two names were different. Earlier I had updated the package name in the first file but forgot to update in the build.gradle file.

Shitul
  • 136
  • 1
  • 4
0

If you are on flutter, take a look on where you initialized your GoogleSignIn, for me adding the clientId parameter worked on iOS but breaks android try that as well

materoy
  • 370
  • 1
  • 3
  • 10
0

If you are having multiple apps under same Project in Firebase, make sure you are in the correct (App)com.xxx.yyy, that matchup with your current project you are doing in Android Studio. Then change the sha1 in settings of Firebase under proper (App)com.xxx.yyy and download the Json accordingly past it at, In project level view apps->build->source.

0

This might come if you have not set the SHA-1/SHA-256 hashes for your project.

0

I double-checked everything on the firebase console, I have correctly added SHA keys also I was facing an error. After spending hours I found the error was due to not setting up OAuth Consent in Google Console. So if any once facing the same issue please check this step as well, that might be your help you out.

enter image description here

Hitesh Dhamshaniya
  • 2,088
  • 2
  • 16
  • 23
0

if above help from other universe can't prevent Google making you fired from your company, below may be help you: edit file "build.gradle" (:app) in android{}, add these if missing, change file path, storePassword, keyAlias, keyPassword

 signingConfigs {
        debug {
            storeFile file('E:\\keystore.jks')
            storePassword '123456'
            keyAlias 'key0'
            keyPassword '123456'
        }
        release {
            storeFile file('E:\\keystore.jks')
            storePassword '123456'
            keyAlias 'key0'
            keyPassword '123456'
        }
    }
 buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.debug
        }
    }

Build/Clean Project Sync Now

if still not working, run Debug app, magical will appear

0

I also faced this problem and search many time but didn't get over this. then I tried firebase authentication and this was worked. try following steps :

go to firebase - go to console(upper right corner) - click on your built app card - then click on authentication and then authenticate your id.

try it.

0

I also faced the same issue, please check if you are using default_web_client_id inside generated resources folder values.xml file. By doing so I resolved my error.

0

In my case, I created a new webclient id in gcp console, which is not work.

Using the one in google-services.json marked with type 3 solves the problem.

The document is very vague about this

davyzhang
  • 2,419
  • 3
  • 26
  • 34