CodetrixStudio / CapacitorGoogleAuth

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

Getting error Something went wrong, code: 10 #291

Open mohamednagy opened 1 year ago

mohamednagy commented 1 year ago

I'm trying to use this package for google sign in. I'm always getting this error

{"save":false,"callbackId":"40115251","pluginId":"GoogleAuth","methodName":"signIn","success":false,"error":{"message":"Something went wrong","code":"10"}}

I tried to follow the documentation as is, here is my configurations:

capacitor.config.json

{
  "appId": "io.ionic.nostashteeb",
  "appName": "Nos Tashteeb",
  "webDir": "dist",
  "bundledWebRuntime": false,
  "plugins": {
    "GoogleAuth": {
      "scopes": ["profile", "email"],
      "iosClientId": "",
      "clientId": "CLIENT_ID.apps.googleusercontent.com",
      "androidClientId": "CLIENT_ID.apps.googleusercontent.com",
      "serverClientId": "CLIENT_ID.apps.googleusercontent.com",
      "forceCodeForRefreshToken": true
    }
  }
}

strings.xml

<string name="server_client_id">CLIENT_ID.apps.googleusercontent.com</string>

MainActivity

registerPlugin(
                com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth.class
        );

and then within my vue application using as

try {
const response = await GoogleAuth.signIn();
} catch (error) {

}

I created my client_id from the google cloud console and copied my SHA1 to the google cloud console but still always getting this error.

capacitor: ^5.1.0 @codetrix-studio/capacitor-google-auth: ^3.3.2

kj1352 commented 1 month ago

After many days of searching & troubleshooting, it finally worked for me too! In my case, firebase is no needed.. i am just getting the "id_token" and sending it to my backend.. then i verify the token and grand access to my user.. so here is what followed: 1) Google console setup Create a web application

  • Set into "Authorized JavaScript origins" & "Authorized redirect URIs" -> http://localhost to be able to test from your browser too, just add your serve port like http://localhost:4200
  • On "Publishing status" set "in production"
  • Now get the web_cllient_id and use it below on each config.GOOGLE_CLIENT_ID reference below

Create an android application (i know make no sense)

  • Set Name & Package name.
  • For the SHA1 go to android studio and use this one keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

2) capacitor.config.ts

plugins: {
    GoogleAuth: {
      scopes: ['profile', 'email'],
      clientId: conf.GOOGLE_CLIENT_ID,
      androidClientId: conf.GOOGLE_CLIENT_ID,
      serverClientId: conf.GOOGLE_CLIENT_ID,
    },
  },

3) Angular component

GoogleAuth.initialize({
      clientId: config.GOOGLE_CLIENT_ID,
      scopes: ['profile', 'email'],
})
async googleSignIn() {
    let googleUser = await GoogleAuth.signIn();
    //todo
}

** On android project have only registered the plugin, nothing else registerPlugin(com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth.class); @OnlinePage You had right! I also used a new key and worked fine! but i also found another one from an old project in case google decides to shut down the new ones (as their warnings) :p

Glad it worked !! đŸ¥³. Ahhh... Google and it's policiesđŸ˜”

Worked like a charm. Thank you. In my case adding android app did it.

This worked for me. Thank you!

ashraful61 commented 1 month ago

For me, the problem solved by using all 3:

clientId: google_web_client_id,
androidClientId: google_web_client_id,
serverClientId: google_web_client_id,

....

Those three are the same ?

mestefanell-rentman commented 3 weeks ago

I had the same issue, the problem was solved by having an android client id (with the sha-1 fingerprint) and a regular web application client id in the google console credentials, while initializing the plugin use the web application client id, but in the capacitor config json I used the android client id.

Also make sure to test this using the corresponding certificates for that sha-1 fingerprint