CodetrixStudio / CapacitorGoogleAuth

Capacitor plugin for Google Auth. Lightweight & no dependencies.
MIT License
257 stars 141 forks source link

Always showing 10:Something Went Wrong error - Ionic5 Capacitor4 Android #220

Open gilzonme opened 1 year ago

gilzonme commented 1 year ago

I am getting always 10:Something Went Wrong error while trying to login to google. Following are the steps I have done and my configurations/versions.

Configurations done in console : image

Capacitor.config.ts : image

What am I missing?

josevavia commented 1 year ago

I have same problem, using version 3.1.4, ionic 5 with capacitor 3. As reference, it seems to work in iOS devices and in browser, the error only occurs in Android device

Any idea?

CodeRevenge commented 1 year ago

It works if you do the next steps:

  1. capacitor.config.ts
const config: CapacitorConfig = {
  ...,
  plugins: {
    GoogleAuth: {
      scopes: ['profile', 'email'],
      androidClientId: "YOUR_WEB_CLIENT_ID.apps.googleusercontent.com",
      iosClientId: "YOUR_IOS_CLIENT_ID.apps.googleusercontent.com",
      forceCodeForRefreshToken: true
    },
  },
};

The CLIENT_ID for ANDROID must be the WEB_CLIENT_ID otherwise it will not work

image

Google Cloud Console/Credentials

  1. Web client Authorized JS Origins

Add your localhost:port to the list

image
  1. strings.xml

Add server_client_id string to the file with your WEB_CLIENT_ID

<string name="server_client_id">YOUR_WEB_CLIENT_ID.apps.googleusercontent.com</string>
  1. MainActivity.java

Import the plugin and use registerPlugin instead of init (init is deprecated)

import com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth;
import com.getcapacitor.BridgeActivity;

public class MainActivity extends BridgeActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        this.registerPlugin(GoogleAuth.class);

        super.onCreate(savedInstanceState);
    }
}

This works for me!

walebey commented 1 year ago

Maybe you´ll find that interesting: https://ionicframework.com/blog/announcing-capacitor-4-0/ New Google Policy will put some pressure to maintain this project by lifting capacitor support to version 4

carsten-klaffke commented 1 year ago

Hey @gilzonme, Are you using Firebase? I have the same problem and think it might be related to my Firebase configuration.

carsten-klaffke commented 1 year ago

Hey @gilzonme, Are you using Firebase? I have the same problem and think it might be related to my Firebase configuration.

It worked for me now.

Did you find the cause? How did you get it working?

EugeneKruglei commented 1 year ago

Same for me... all those solutions don't work :( Cap 4 Ionic 6

EugeneKruglei commented 1 year ago

Unable to find a Capacitor plugin to handle requestCode, trying Cordova plugins Sending plugin error: {"save":false,"callbackId":"120447529","pluginId":"GoogleAuth","methodName":"signIn","success":false,"error":{"message":"Something went wrong","code":"12500"}} 2022-08-26 01:39:28.301 3167-3167/io.lewapp.vocabulary D/Capacitor/AppPlugin: Firing change: true 2022-08-26 01:39:28.301 3167-3167/io.lewapp.vocabulary V/Capacitor/AppPlugin: Notifying listeners for event appStateChange 2022-08-26 01:39:28.301 3167-3167/io.lewapp.vocabulary D/Capacitor/AppPlugin: No listeners found for event appStateChange 2022-08-26 01:39:28.301 3167-3167/io.lewapp.vocabulary D/Capacitor: App resumed 2022-08-26 01:39:28.318 3167-3167/io.lewapp.vocabulary E/Capacitor/Console: File: http://localhost/vendor.js - Line 83313 - Msg: ERROR Error: Uncaught (in promise): Error: Something went wrong Error: Something went wrong at returnResult (http://localhost/:422:32) at Object.win.androidBridge.onmessage (http://localhost/:397:21)

carsten-klaffke commented 1 year ago

I got it running now by stepping back to a Capacitor 3 version of my code and the re-executed the Cap4 migration. Maybe there was a problem with Capacitor that got fixed in the last days, because I carefully tracked my code changes and didn't see anything that could've caused the GoogleAuth problems. Suspiciously, when GoogleAuth gave me that 10-error-code, my Facebook login didn't work as well. The Facebook login errored out because of a wrong hash. So I think that somehow with the Cap4 migration the hashing of security keys got broken and that caused the 10-error-code at GoogleAuth.

EugeneKruglei commented 1 year ago

@carsten-klaffke somehow the issue was solved... I kept all the same configs(recommended setup config as described by @CodeRevenge here... Just removed all testing virtual devices Re-added it again - TiramisuPrivacySandbox

image

And... At the first start again an error... I logged-in in PlayMarket on the emulator - it works! Tomorrow I'll try to test the app on a real device... Need to try clearing/resetting default settings...

ludufre commented 1 year ago

It works if you do the next steps:

  • capacitor: 3.5.1 , perhaps this works in v4
  • ionic: 5
  • CapacitorGoogleAuth: 3.1.4
  1. capacitor.config.ts
const config: CapacitorConfig = {
  ...,
  plugins: {
    GoogleAuth: {
      scopes: ['profile', 'email'],
      androidClientId: "YOUR_WEB_CLIENT_ID.apps.googleusercontent.com",
      iosClientId: "YOUR_IOS_CLIENT_ID.apps.googleusercontent.com",
      forceCodeForRefreshToken: true
    },
  },
};

The CLIENT_ID for ANDROID must be the WEB_CLIENT_ID otherwise it will not work

image

Google Cloud Console/Credentials

  1. Web client Authorized JS Origins

Add your localhost:port to the list image

  1. strings.xml

Add server_client_id string to the file with your WEB_CLIENT_ID

<string name="server_client_id">YOUR_WEB_CLIENT_ID.apps.googleusercontent.com</string>
  1. MainActivity.java

Import the plugin and use registerPlugin instead of init (init is deprecated)

import com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth;
import com.getcapacitor.BridgeActivity;

public class MainActivity extends BridgeActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        this.registerPlugin(GoogleAuth.class);

        super.onCreate(savedInstanceState);
    }
}

This works for me!

This is still the solution in Capacitor 4

mircoba commented 1 year ago

On our side the underlying issue was that somehow the SHA1 of our app changed with capacitor 4 migration. We had to add the new fingerprint to the Android App settings in firebase console and then the login was working again.

Reference: https://stackoverflow.com/questions/49450140/google-signin-api-exception-10

Joep-DDQ commented 1 year ago

In addition to the WEB Client ID you MUST have the SHA-1 Android key in GCloud added in the OAuth credentials even though the Android client ID is never mentioned anywhere in the Capacitor Google Auth code.

One other thing I ran into was that the key didn't transfer correctly from the changes in the capacitor.config.ts file to the android files. Make sure you run ionic capacitor build android to do this.

I only have the

  1. clientId in capacitor.config.json
  2. (androidClientId in my capacitor.config.ts file). not sure if this one is used
  3. server_client_id in strings.xml
  4. clientId in the init code for the plugin (for Web platform)

All of them the web client ID value.

timeisgolden commented 1 year ago

Hello, @EugeneKruglei I am facing the same issue, the above suggestions didn't help me. I am using @ionic/angular@6.1.9, capacitor4.2.0, @codetrix-studio/capacitor-google-auth@3.2.0. Did you solve the Google Login issue?

Epameinondas-Theodoropoulos commented 1 year ago

Same problem. Can someone suggest something else ?

daniromome commented 1 year ago

I managed to resolve this issue deleting the android app I previously created in the overview page of my project in firebase and creating it again with the app id, sha1 and app name.

pratikbhalodiya commented 1 year ago

The same issue... Using Capacitor 4

image

Also used android key and WebClient key

Epameinondas-Theodoropoulos commented 1 year ago

Apaparently there is an error between the debug.keytore and the release.keystore. When I add the debug.keystore in the google console (OAuth 2.0 Client IDs - Android Client) and I build the grandle with this in android studio, everything works. But when I add the release.keystore in the google console , it only works for the web and not for android or ios. What is going on? This is very weird.

Can anyone help ?

renehauck commented 1 year ago

I also had problems, but the video helped me. For me, the problem was that an "Authorised JavaScript sources" was missing in the gcp console.

https://www.youtube.com/watch?v=Ay9F6WHfnkU

jeromebon commented 1 year ago

We had the same issue. We fixed it by setting the androidClientId to the server_client_id value.

Diffing 3.0.2 and 3.2.0 shows that the clientId was read from server_client_id and is now androidClientId.

In 3.0.2:

String clientId = this.getContext().getString(R.string.server_client_id);

became in 3.2.0

String clientId = getConfig().getString("androidClientId",
      getConfig().getString("clientId",
        this.getContext().getString(R.string.server_client_id)));
Saqib92 commented 1 year ago

Facing Same error on Release build only.

When building debug build on mobile and adding debug SHA-1 to google console received from android studio it works. But when release on playstore and adding SHA-1 from developer console it shows error 10. What exactly i am missing here?

what exactly is the javascript origin? i have added default one http://localhost:8100 as my origin.

selcuk-sahin commented 1 year ago

When building debug build on mobile and adding debug SHA-1 to google console received from android studio it works. But when release on playstore and adding SHA-1 from developer console it shows error 10. What exactly i am missing here?

@Saqib92 I think your issue is different. The behavior you get is expected, since Google Play generates a different SHA-1. You should also find & and that to the console.

Saqib92 commented 1 year ago

When building debug build on mobile and adding debug SHA-1 to google console received from android studio it works. But when release on playstore and adding SHA-1 from developer console it shows error 10. What exactly i am missing here?

@Saqib92 I think your issue is different. The behavior you get is expected, since Google Play generates a different SHA-1. You should also find & and that to the console.

where can i find it in Google Play?

selcuk-sahin commented 1 year ago

When building debug build on mobile and adding debug SHA-1 to google console received from android studio it works. But when release on playstore and adding SHA-1 from developer console it shows error 10. What exactly i am missing here?

@Saqib92 I think your issue is different. The behavior you get is expected, since Google Play generates a different SHA-1. You should also find & and that to the console.

where can i find it in Google Play?

There are multiple ways,

From Google Cloud Console: 1 - Go to Google Cloud Console and log in with your Google Sign-in account. 2- Select the related project from the top (this could be a firebase/google cloud project) 3- Search for API/s clients 4- From the left menu select Credentials 5- In this menu you should see list of autogenerated items under OAuth 2.0 Client IDs. Select the relevant client & you will see the SHA1 key here.

From the APK: 1- Download the APK from Google Play Store. This medium article might help. 2- Learn the SHA1 from this APK, you can use install & use keytool here. SO post

Saqib92 commented 1 year ago

When building debug build on mobile and adding debug SHA-1 to google console received from android studio it works. But when release on playstore and adding SHA-1 from developer console it shows error 10. What exactly i am missing here?

@Saqib92 I think your issue is different. The behavior you get is expected, since Google Play generates a different SHA-1. You should also find & and that to the console.

where can i find it in Google Play?

There are multiple ways,

From Google Cloud Console: 1 - Go to Google Cloud Console and log in with your Google Sign-in account. 2- Select the related project from the top (this could be a firebase/google cloud project) 3- Search for API/s clients 4- From the left menu select Credentials 5- In this menu you should see list of autogenerated items under OAuth 2.0 Client IDs. Select the relevant client & you will see the SHA1 key here.

From the APK: 1- Download the APK from Google Play Store. This medium article might help. 2- Learn the SHA1 from this APK, you can use install & use keytool here. SO post

looks like I already done almost same.

cihakmar commented 1 year ago

Someone with the same error still? I have set client id for android the same as fo web but always code 10 error. Onl yandroid do not work. web and iOS is fine

ProjectHammer commented 1 year ago

Why do I need to use firebase to fix this error, I tried everything so far.. nothing works still errors .. 10

abhisant commented 1 year ago

MainActivity.java

public class MainActivity extends BridgeActivity { public void onCreate(Bundle savedInstanceState) { registerPlugin(GoogleAuth.class); super.onCreate(savedInstanceState); } }

Strings.xml added -

Added web_cilent_id

Created the following - (but didn't use Andriod client id anywhere).

image

It works for web, ios, but doesn't work for Android.

It gives the following error -- D/CompatibilityChangeReporter: Compat change id reported: 78294732; UID 10159; state: ENABLED D/Capacitor: Unable to find a Capacitor plugin to handle requestCode, trying Cordova plugins 147138663 D/Capacitor: Sending plugin error: {"save":false,"callbackId":"1887292","pluginId":"GoogleAuth","methodName":"signIn","success":false,"error":{"message":"Something went wrong","code":"10"}}

ProjectHammer commented 1 year ago

MainActivity.java

public class MainActivity extends BridgeActivity { public void onCreate(Bundle savedInstanceState) { registerPlugin(GoogleAuth.class); super.onCreate(savedInstanceState); } }

Strings.xml added - Added web_cilent_id

Created the following - (but didn't use Andriod client id anywhere). image

It works for web, ios, but doesn't work for Android.

It gives the following error -- D/CompatibilityChangeReporter: Compat change id reported: 78294732; UID 10159; state: ENABLED D/Capacitor: Unable to find a Capacitor plugin to handle requestCode, trying Cordova plugins 147138663 D/Capacitor: Sending plugin error: {"save":false,"callbackId":"1887292","pluginId":"GoogleAuth","methodName":"signIn","success":false,"error":{"message":"Something went wrong","code":"10"}}

I think google deprecated use .. on google console code 10 had a message saying no longer supported.

sachinkannaujiya98 commented 1 year ago

I am using google auth in ionic ,sign in with google popup is opening but its throwing error message: 'Something went wrong', code: '10'

ProjectHammer commented 1 year ago

Yes webview isn't supported in Auth anymore due to security, you can't handle the response from outside of the android unless you handle it somewhere else .. you'll have to handle the code inside androids Java..

pad01g commented 1 year ago

In my case it was mismatch of package_name in android/app/src/main/res/values/strings.xml, config.appId in capacitor.config.ts, and package name in google dev console. At least I could get token response from server by fixing these.

i-timur commented 10 months ago

Yes webview isn't supported in Auth anymore due to security, you can't handle the response from outside of the android unless you handle it somewhere else .. you'll have to handle the code inside androids Java..

Any reference on this?

LucaDaniele99 commented 10 months ago

Had the same issue. I've implemented @ludufre 's answer and after I created a new credentials on G Cloud Console as Android app and added the SHA-1 of the app certificate I use to sign the app. After generating and installing the signed APK on a real device then GAuth works fine, it doesn't work if runned directly from Android Studio as it is installed as a debug version so it's not signed.

danny-hunt commented 10 months ago

If you are using Google Play Store App Signing, then the released version will use GOOGLE'S certificate SHA1 rather than the SHA1 from your release keystore. (Which makes sense when you think about it...)

I encountered this when trying to release through google play, even though it was previously working on emulator in debug.

You can find that SHA1 by going to MY_APP > Setup > App signing > App signing. Using that solved ~all~ my problem~s~

Edit: Also check out @LucaDaniele99's comment below! (I haven't gone back to check who is right yet 😅)

LucaDaniele99 commented 10 months ago

@danny-hunt on Play Store I'm using Google App Signing but on GCloud I've inserted the SHA-1 keystore I use to sign the app in Android Studio so both of the SHA-1 works I think

Pxeba commented 7 months ago

Yes webview isn't supported in Auth anymore due to security, you can't handle the response from outside of the android unless you handle it somewhere else .. you'll have to handle the code inside androids Java..

nop. continues to work. I'm using ionic 7 with capacitor and I've been getting error 10. I tried the previous solutions but discovered that my problem was a typo in the package name. ("strings.xml" file)

So just to clarify. Do not use the gcp android client_id, but it is necessary to create it and make sure to use the corresponding debug/release.

harryt2 commented 7 months ago

In my case I needed to add Google and Apple as authentication providers in Firebase Screenshot 2023-09-29 at 5 44 58 PM

ChamaraDissanayake commented 7 months ago

This issue occurred me when I trying to release my app on play store (Internal testing).

Error: 10

Screenshot 2023-10-10 at 10 08 17

I fixed it by adding play store generated SHA-1 and SHA-256 keys to my firebase android app.

Screenshot 2023-10-10 at 09 49 24 Screenshot 2023-10-10 at 09 46 16

piotr-cz commented 6 months ago

This error was showing for me up when I've been running app from Android Studio.

I fixed it by adding OAuth Client ID (Android) in Google Cloud Console credential with SHA1 of my debug keystore (C:\Users\{username}\.android\debug.keystore):

cd android
./gradlew signingReport

Also this video helped me to set everything up: https://www.youtube.com/watch?v=GwtpoWZ_78E

erickqe commented 6 months ago

Still not working, you send the app a couple of people and start showing the 'Something went wrong' msg

RkyErtm commented 6 months ago

It doesn't work in my project either.

Saqib92 commented 6 months ago

It is very simple: 1). Always use debug SHA-1 from your Android Studio if you are on Debug build to generate APK for testing. this will change if you change your computer like if you make APK form new computer your SHA-1 will be chnaged.

2). When upload your app to playstore change your SHA-1. Copy it from google play console and paste it in google developer console where you created android client id.

ciekawy commented 6 months ago

for anyone struggling with this. I'm 99% sure that

I think it deserves double checking but IMO this is how the docs should be updated to save tons of time people struggling with this.

wouterbin commented 5 months ago

for anyone struggling with this. I'm 99% sure that

This is true. Thanks a lot! 👍

So in the https://console.cloud.google.com/apis/credentials You create two "OAuth 2.0 Client IDs". One with type "Web application" and one with type "Android".

For the "Android" type set the right "Package name" and "SHA1 certificate fingerprint".

In capacitor.config.json set the Client ID from the "Web Application" type:

"GoogleAuth": {
      "scopes": [
        "email",
        "profile"
      ],
      "clientId": "REPLACE_ME.apps.googleusercontent.com"
    }
 }

Don't ask me why it works like this, it does 😊

bakicdj commented 5 months ago

It works if you do the next steps:

  • capacitor: 3.5.1 , perhaps this works in v4
  • ionic: 5
  • CapacitorGoogleAuth: 3.1.4
  1. capacitor.config.ts
const config: CapacitorConfig = {
  ...,
  plugins: {
    GoogleAuth: {
      scopes: ['profile', 'email'],
      androidClientId: "YOUR_WEB_CLIENT_ID.apps.googleusercontent.com",
      iosClientId: "YOUR_IOS_CLIENT_ID.apps.googleusercontent.com",
      forceCodeForRefreshToken: true
    },
  },
};

The CLIENT_ID for ANDROID must be the WEB_CLIENT_ID otherwise it will not work

image

Google Cloud Console/Credentials

  1. Web client Authorized JS Origins

Add your localhost:port to the list image

  1. strings.xml

Add server_client_id string to the file with your WEB_CLIENT_ID

<string name="server_client_id">YOUR_WEB_CLIENT_ID.apps.googleusercontent.com</string>
  1. MainActivity.java

Import the plugin and use registerPlugin instead of init (init is deprecated)

import com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth;
import com.getcapacitor.BridgeActivity;

public class MainActivity extends BridgeActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        this.registerPlugin(GoogleAuth.class);

        super.onCreate(savedInstanceState);
    }
}

This works for me!

I lost 1.5 days on this. I made it work finally by putting the web client id to the android id in my capacitor config:

"plugins": { "GoogleAuth": { "clientId": "ANDROID_CLIENT_ID_I_DONT_KNOW_IF_IT_IS_OK_BUT_IT_WORKS.apps.googleusercontent.com", "androidClientId": "WEB_CLIENT_ID_FOR_SOME_REASON.apps.googleusercontent.com", "scopes": [ "profile", "email" ], "serverClientId": "WEB_CLIENT_ID.apps.googleusercontent.com", "forceCodeForRefreshToken": true }

KKzLEO commented 4 months ago

It works if you do the next steps:

  • capacitor: 3.5.1 , perhaps this works in v4
  • ionic: 5
  • CapacitorGoogleAuth: 3.1.4
  1. capacitor.config.ts
const config: CapacitorConfig = {
  ...,
  plugins: {
    GoogleAuth: {
      scopes: ['profile', 'email'],
      androidClientId: "YOUR_WEB_CLIENT_ID.apps.googleusercontent.com",
      iosClientId: "YOUR_IOS_CLIENT_ID.apps.googleusercontent.com",
      forceCodeForRefreshToken: true
    },
  },
};

The CLIENT_ID for ANDROID must be the WEB_CLIENT_ID otherwise it will not work

image

Google Cloud Console/Credentials

  1. Web client Authorized JS Origins

Add your localhost:port to the list image

  1. strings.xml

Add server_client_id string to the file with your WEB_CLIENT_ID

<string name="server_client_id">YOUR_WEB_CLIENT_ID.apps.googleusercontent.com</string>
  1. MainActivity.java

Import the plugin and use registerPlugin instead of init (init is deprecated)

import com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth;
import com.getcapacitor.BridgeActivity;

public class MainActivity extends BridgeActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        this.registerPlugin(GoogleAuth.class);

        super.onCreate(savedInstanceState);
    }
}

This works for me!

My project doesn't have strings.xml and I can't import import com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth; in MainActivity.java. I'm using Nextjs + Capacitor. Can you kindly tell where I am wrong? should I install ionic?

capacitor version: 5.6.0

image

evd3v commented 1 month ago

It works if you do the next steps:

  • capacitor: 3.5.1 , perhaps this works in v4
  • ionic: 5
  • CapacitorGoogleAuth: 3.1.4
  1. capacitor.config.ts
const config: CapacitorConfig = {
  ...,
  plugins: {
    GoogleAuth: {
      scopes: ['profile', 'email'],
      androidClientId: "YOUR_WEB_CLIENT_ID.apps.googleusercontent.com",
      iosClientId: "YOUR_IOS_CLIENT_ID.apps.googleusercontent.com",
      forceCodeForRefreshToken: true
    },
  },
};

The CLIENT_ID for ANDROID must be the WEB_CLIENT_ID otherwise it will not work

image

Google Cloud Console/Credentials

  1. Web client Authorized JS Origins

Add your localhost:port to the list image

  1. strings.xml

Add server_client_id string to the file with your WEB_CLIENT_ID

<string name="server_client_id">YOUR_WEB_CLIENT_ID.apps.googleusercontent.com</string>
  1. MainActivity.java

Import the plugin and use registerPlugin instead of init (init is deprecated)

import com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth;
import com.getcapacitor.BridgeActivity;

public class MainActivity extends BridgeActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        this.registerPlugin(GoogleAuth.class);

        super.onCreate(savedInstanceState);
    }
}

This works for me!

I lost 1.5 days on this. I made it work finally by putting the web client id to the android id in my capacitor config:

"plugins": { "GoogleAuth": { "clientId": "ANDROID_CLIENT_ID_I_DONT_KNOW_IF_IT_IS_OK_BUT_IT_WORKS.apps.googleusercontent.com", "androidClientId": "WEB_CLIENT_ID_FOR_SOME_REASON.apps.googleusercontent.com", "scopes": [ "profile", "email" ], "serverClientId": "WEB_CLIENT_ID.apps.googleusercontent.com", "forceCodeForRefreshToken": true }

thanks bro! you've saved my day :)

Raja-Malli-Dileep-Vadde commented 1 week ago

Actually, i am also totally confused about google signing in ionic app but, i got to know solution by several tries for four months, i finally discovered that the debug keystore SHA1 only works in the emulator

Here, https://github.com/CodetrixStudio/CapacitorGoogleAuth/issues/332#issuecomment-2098010545