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

31

95

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]
                }
            });
}
Lowrey answered 3/12, 2017 at 14:12 Comment(7)
Basically problem is in the SHA1 key put on console please regenerate it and put again properly same projectPartake
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??Lowrey
which solution did u follow to fix the issueStrophe
@Strophe the accepted oneLowrey
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 meThrive
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 ?Indisposed
@Indisposed no, I don'tThrive
P
120

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

Partake answered 3/12, 2017 at 16:20 Comment(8)
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.Anastase
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.Haslett
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 tryForgiveness
@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.Strophe
Make sure you are using the correct keystore file's fingerprint in console. (for me, flutter uses one in ~/.android/debuge.keystore)Loon
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.Tanya
Linking my project to Google Play solved a persistent and confusing issue for me. Thank you so much!Fledgling
Can you elaborate on option (2) I can seem to find Account Linking tab when clicking on the gear iconVeraveracious
U
33

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

Uganda answered 6/2, 2019 at 13:50 Comment(6)
Thanks a lot. It saved me. I am about to panic!Mccowan
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!Nola
@Nola 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?Typhoon
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.Typhoon
Dude... finally found this after 20+ hours of not figuring it out, thank you.Genesia
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: stackoverflow.com/a/72440651Copper
A
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();
Absorbing answered 16/2, 2019 at 11:12 Comment(2)
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.Columbian
Don't know but I faced this issue, and spend too much time on this issue. I solved the issue on my own.Absorbing
N
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

Naldo answered 16/12, 2017 at 21:8 Comment(3)
this one is importantLisalisabet
I just fixed this same mistake.Polito
Yes, there are 3 SHA-1s! stackoverflow.com/a/72440651Copper
D
11

My solution was a little different,

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

Using the steps listed here: https://mcmap.net/q/10304/-how-to-get-the-sha-1-fingerprint-certificate-in-android-studio-for-debug-mode

  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.

Dockhand answered 30/11, 2019 at 20:30 Comment(3)
Specifically For React Native project app.box.com/s/vf9ez8h8u9ran38ltk5hyupmuwq8bw3lBessiebessy
It's 2022 and the SHA1 that you want is no longer in gradle. It's actually in Play Console itself. See stackoverflow.com/a/72440651Copper
This is my solution, too. It's workedWoodwork
C
6

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

Copper answered 30/5, 2022 at 22:42 Comment(1)
Its 2023, and i got saved by your answer. adding a third credential worked. Who made this??Deaf
H
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

Harbour answered 4/6, 2019 at 8:36 Comment(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 errorNook
this is the one answer. THANK YOU.Teplitz
T
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 ;)

Tribadism answered 1/8, 2019 at 19:40 Comment(0)
J
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
Jimmy answered 18/7, 2020 at 4:52 Comment(0)
M
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

Myalgia answered 13/1, 2020 at 19:48 Comment(0)
D
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 :)

Demobilize answered 26/3, 2020 at 23:8 Comment(0)
C
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

Conduce answered 26/7, 2020 at 4:23 Comment(0)
U
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

Undervest answered 31/5, 2022 at 1:40 Comment(0)
S
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

Snowball answered 20/2, 2019 at 16:36 Comment(0)
E
1

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

Elector answered 2/3, 2020 at 18:33 Comment(1)
Thanks, I added Android Oauth 2.0 with package name and SHA1 and then I used the client ID from the web application, which works as intended.Giltedged
S
1

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

Selfsustaining answered 12/7, 2020 at 10:57 Comment(0)
S
1

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

Schargel answered 4/4, 2021 at 12:39 Comment(0)
A
1

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

Atilt answered 6/1, 2022 at 16:34 Comment(0)
W
1

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

As others have said, you need to add your SHA key to your Firebase project for this. But if you are still getting this error even after adding SHA, then please check whether you have enabled Sign in with Google in the Authentication section of your Firebase project. This was the issue in my case.

Wimberly answered 4/3 at 15:57 Comment(0)
P
1

com.google.android.gms.common.api.ApiException: 10: Developer console is not set up correctly.

this exception is usually because your android studio SHA1 is not added in firebase project.

I faced this when i tried to build the same app from my different laptop,

just go to firebase console > project settings

under General tab, add the new SHA1 fingerprint

Physicist answered 3/4 at 17:3 Comment(0)
S
0

In my case to work on the emulator, I followed the steps https://mcmap.net/q/10304/-how-to-get-the-sha-1-fingerprint-certificate-in-android-studio-for-debug-mode, 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

Spacial answered 20/8, 2019 at 9:18 Comment(0)
V
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.

Vandalism answered 8/5, 2020 at 2:39 Comment(0)
R
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.

Refugee answered 1/8, 2020 at 13:39 Comment(0)
R
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.

Riding answered 16/3, 2021 at 4:34 Comment(0)
M
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.

Malca answered 4/7, 2021 at 6:3 Comment(0)
P
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

Pham answered 28/4, 2022 at 14:21 Comment(0)
L
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

Lathy answered 11/7, 2022 at 7:9 Comment(0)
W
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.

Whitacre answered 12/11, 2022 at 18:13 Comment(0)
A
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.

Ancillary answered 10/3, 2023 at 8:26 Comment(0)
H
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

Hildahildagard answered 12/4, 2023 at 9:29 Comment(0)
S
0

I got my solution by changing my sha1 in the firebase console setting, u can done by

step 1: get the sha1 from your android studio

step 2: update in the firebase console by project overview> project setting> scroll down delete the last old sha1 and update what u got from the step1

step 3: redownload the google-services.json file and update in your android studio project

Sphalerite answered 15/12, 2023 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.