captainhaddockfr35 / nativescript-google-login

Apache License 2.0
2 stars 5 forks source link

Gmail account selection keeps triggering 'cancelled' #12

Open BHuys opened 4 years ago

BHuys commented 4 years ago

Which platform(s) does your issue occur on?

Android

Info

I'm getting the popup where an account can be selected to show up, but when I tap on my account the loginprocedure gets 'cancelled'. Am I missing something?

code-snippets

//init GoogleLogin.init({ google: { initialize: true, serverClientId: xxxxx, clientId: xxxx, isRequestAuthCode: false }, activity: application.android.foregroundActivity });

//login button GoogleLogin.login(result=>{ console.dir(result); });

logs

JS: 'Starting activity for result...' JS: 'Cancelled' JS: 'result. provider = google' 'onActivityResult()' JS: 'result. code = 1' 'onActivityResult()' JS: 'Calling Callback function with Results' JS: ==== object dump start ==== JS: provider: "google" JS: code: "1" JS: ==== object dump end ====

RustamAkimov commented 4 years ago

@BHuys got similar problem... this part of similar plugin preparation helped me: https://github.com/mkloubert/nativescript-social-login#setup-android-google-sign-in-for-debug-builds

dereekb commented 4 years ago

I'm having the same issue. @RustamAkimov are you using a serverClientId with your request also?

I can get it to work when just passing only the clientId, but once I pass it the serverClientId the login attempts return {"provider":"google","code":1}.

It works on iOS fine, but I can't get it to work with Android.

dereekb commented 4 years ago

I got it resolved.

Turns out the OAuth 2.0 Client IDs I was using had a type of Other instead of Web Application. For whatever reason, the Android implementation of the Google Login will immediately reject using that server id, while the iOS version will not.

On Android you only need to use serverClientId and don't have to pass a clientId if you're using it to get an authCode.

It doesn't seem like specifying a certificate fingerprint is even necessary if you're doing server-side verification. @BHuys double check that the client ID you're using is the same one that is for your server, and also that it has the type Web Application.

odedBartov commented 3 years ago

I got it resolved.

Turns out the OAuth 2.0 Client IDs I was using had a type of Other instead of Web Application. For whatever reason, the Android implementation of the Google Login will immediately reject using that server id, while the iOS version will not.

On Android you only need to use serverClientId and don't have to pass a clientId if you're using it to get an authCode.

It doesn't seem like specifying a certificate fingerprint is even necessary if you're doing server-side verification. @BHuys double check that the client ID you're using is the same one that is for your server, and also that it has the type Web Application.

Can you PLEASE(X10) show me an example? i still can't make it work. i am trying this way:

GoogleLogin.init({
            google: {
                clientId: "",
                serverClientId: "my_client_id_from_OAuth_android_credentials_i_created.apps.googleusercontent.com",
                isRequestAuthCode: true
            },
            onActivityResult: undefined,
            activity: application.android.foregroundActivity
        })

i keep getting this result:

Cancelled
result. provider = google onActivityResult()
result. code = 1 onActivityResult()
Calling Callback function with Results
 {
   "provider": "google",
   "code": 1
 }

I tried using api of Android and of Web client but got the same result with both

odedBartov commented 3 years ago

Which platform(s) does your issue occur on?

Android

Info

I'm getting the popup where an account can be selected to show up, but when I tap on my account the loginprocedure gets 'cancelled'. Am I missing something?

code-snippets

//init GoogleLogin.init({ google: { initialize: true, serverClientId: xxxxx, clientId: xxxx, isRequestAuthCode: false }, activity: application.android.foregroundActivity });

//login button GoogleLogin.login(result=>{ console.dir(result); });

logs

JS: 'Starting activity for result...' JS: 'Cancelled' JS: 'result. provider = google' 'onActivityResult()' JS: 'result. code = 1' 'onActivityResult()' JS: 'Calling Callback function with Results' JS: ==== object dump start ==== JS: provider: "google" JS: code: "1" JS: ==== object dump end ====

hi, i am having the exact same problem. Did you find any solution?

AgustinV08 commented 3 years ago

@odedBartov Are testing in production build?

odedBartov commented 3 years ago

@odedBartov Are testing in production build?

No, why?

AgustinV08 commented 3 years ago

In the Google Console you have to insert your keystore Sha-1 string, if you test your app in a production build using the keystore the google login will work

tripper-app commented 3 years ago

In the Google Console you have to insert your keystore Sha-1 string, if you test your app in a production build using the keystore the google login will work

I am not sure i understand you. What is the actuall difference between release build and debug build? I did insert the Sha-1 string in the google console. Anyway, i built the app with the keystore but still bumped into the same problem... it didn't solved it

AgustinV08 commented 3 years ago

Do you hace your init function like this for android?

GoogleLogin.init({
    google: {
        initialize: true,
        isRequestAuthCode: true,
        clientId: google_login.android,
        serverClientId: google_login.server_client_id
    },
    viewController: Application.android.foregroundActivity
});
tripper-app commented 3 years ago

Do you hace your init function like this for android?

GoogleLogin.init({
    google: {
        initialize: true,
        isRequestAuthCode: true,
        clientId: google_login.android,
        serverClientId: google_login.server_client_id
    },
    viewController: Application.android.foregroundActivity
});

Yes, exept the clientId which i left empty

AgustinV08 commented 3 years ago

Try including the clientID from the Google Console, Android OAuth Key

tripper-app commented 3 years ago

I already did, same result

mrzanirato commented 3 years ago

Hello, we have the same issue even with a production app. Any news? Thanks

shahen94 commented 3 years ago

I had the same issue

Here's the solution

  1. Open Google Developer Console
  2. Create Credentials for Web Application - Do not create for Android
  3. Copy client id
  4. in the init function use the following code

image

That's it

mrzanirato commented 3 years ago

Thanks @shahen94, I tried your config without any luck. In the Google Developer Console I had both Android ID and Server ID so I deleted the Android ID I also generated a new Web Application ID but it didn't work

Any idea?

Thanks

shahen94 commented 3 years ago

@mrzanirato can you please try to remove app and install again?

mrzanirato commented 3 years ago

I tried but nothing ... here is my console log

JS: Will request ID token JS: Google Login JS: Starting activity for result... JS: Cancelled JS: result. provider = google onActivityResult() JS: result. code = 1 onActivityResult() JS: Calling Callback function with Results JS: Error: Unexpected HTTP status code (404)

mrzanirato commented 3 years ago

Just to be sure I also tried building a release apk ... same problem

mrzanirato commented 3 years ago

@shahen94 do you have a working example app to test? Thanks

mrzanirato commented 3 years ago

Hello @shahen94 can you confirm that the code is actually working in Android? Thanks

mrzanirato commented 3 years ago

@pboulch can you please check if the plugin is still working in Android? Thanks

agardes commented 2 years ago

I had the same issue

Here's the solution

  1. Open Google Developer Console
  2. Create Credentials for Web Application - Do not create for Android
  3. Copy client id
  4. in the init function use the following code

image

That's it

@mrzanirato I managed to fix the problem following @shahen94 comment, I deleted the clientId field, and wait a bit (like 10 min) for the Web Application serverClientId to be ready on Google Console.