CodetrixStudio / CapacitorGoogleAuth

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

GoogleAuth.signIn Ionic 6 Android - "Something went wrong","code":"10" #289

Closed abhisant closed 1 year ago

abhisant commented 1 year ago

I have been stuck on this for a while. I am using IONIC 6, Sign in With Google works for IOS and Web but doesn't work for Android. Can someone guide how to proceed? I need to get it working in Android using IONIC.


{message: 'Something went wrong', code: '10'}

These are the changes that I have made:

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

I 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"}}

AlvinTCH commented 1 year ago

When it's code "10" in Android, its usually a SHA-1 issue. Do check if your SHA-1 is configured properly where there is 1 inside google play if you configure the app to be signed under google play, and another in your android studio which you use to debug.

If the above is true, then make sure both SHA-1 are inside the cloud console, which you will need to create 2 separate android configurations to take it in.

I do recommend using firebase to create the cloud console configuration for this as the UI makes it more straight forward and helps to avoid mistakes that are otherwise hard to spot if you create credentials on the cloud console directly

This issue in another repo might be able to help you understand it better: https://github.com/googlesamples/google-services/issues/360

abhisant commented 1 year ago

Thanks @AlvinTCH My app is still under development, it's not yet published to Google Play Store.

I generated SHA1 using the following tool -

image

I copied the value of - "SHA1: " in the following -

image
AlvinTCH commented 1 year ago

is your android app client id using the android client id or the web id?

abhisant commented 1 year ago

Web id @AlvinTCH

I have made changes to Strings.xml too with web client id

jrodriguer commented 1 year ago

Same problem, my project with capacitor response with error code 10.

Me too changes in strings.xml file with web client id.

Capacitor config: { "appId": "", "appName": "", "webDir": "www", "bundledWebRuntime": false, "allowMixedContent": true, "plugins": { "GoogleAuth": { "scopes": ["profile", "email"], "iosClientID": "", "androidClientID": "webclientid.apps.googleusercontent.com" } } }

abhisant commented 1 year ago

It worked finally. I deleted the android directly and recreated it using ionic commands. Made changes to MainActivity and Strings.xml.

@jrodriguer this is my capacitor config.

{ "appId": "<>", "appName": "<>", "webDir": "build", "bundledWebRuntime": false, "plugins": { "GoogleAuth": { "scopes": ["profile","email"], "clientId" : "IOS_CLIENT_ID.apps.googleusercontent.com", (needed for ios - value is ios client id) "serverClientId": "WEB_CLIENT_D.apps.googleusercontent.com", (needed for android - the value is webclientid and not android) "forceCodeForRefreshToken": true } } }

@jrodriguer - "androidClientID" should be replaced with "serverClientId"

SossenSystems commented 1 year ago

When it's code "10" in Android, its usually a SHA-1 issue. Do check if your SHA-1 is configured properly where there is 1 inside google play if you configure the app to be signed under google play, and another in your android studio which you use to debug.

If the above is true, then make sure both SHA-1 are inside the cloud console, which you will need to create 2 separate android configurations to take it in.

I do recommend using firebase to create the cloud console configuration for this as the UI makes it more straight forward and helps to avoid mistakes that are otherwise hard to spot if you create credentials on the cloud console directly

This issue in another repo might be able to help you understand it better: googlesamples/google-services#360

I think that you have done me a great favour!

IDENTICOSantiago commented 3 months ago

Hello, I have a similar problem, all this time I thought that the problem was when I published my application to the play store that it stopped working, since in APK and emulator it always worked but when I tried to log in with Google from my application it showed me an error 10, but I realized that it is something different and the problem was not with the play store. It's like the system crashes or something because sometimes it works and when it works it works everywhere but when it crashes or I don't know what happens it stops working in all types of environments and throws error 10.

I'm only using Google Cloud for now, but I plan to use FireBase if this problem continues, if anyone knows how I can solve this problem it would be very helpful.

I am using the SHA1 of the release that returns the signinReport of android studio in Google Cloud and from what I see the package name, the fingerprint and the id of the web type client are correct.