EddyVerbruggen / cordova-plugin-googleplus

:heavy_plus_sign: Cordova plugin to login with Google Sign-In on iOS and Android
567 stars 629 forks source link

Cannot connect on iOS, works fine on Android #640

Open Aghamyr opened 5 years ago

Aghamyr commented 5 years ago

Hi, I have a weird issue with my Ionic application. Users cannot use google plus login on iOS version of the app but the Android version works just fine. It takes the user to the google account login/select page but after the login it returns to the app and generates an error on iOS.

I have looked around for similar problems but only found people with the reverse problem where iOS works but not Android and I'm at a loss here, so I though I'd try my chance here and ask for help.

So far I've tried a few of the different versions of the googleplus plugins but without success, I've double checked that the reversed key is correct too. I also don't get an error code from the connect attemps, the error is set as "undefined".

Here is the Ionic install :


   ionic (Ionic CLI)  : 4.12.0
   Ionic Framework    : ionic-angular 3.9.5
   @ionic/app-scripts : 3.2.3

Cordova:

   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : android 7.1.4, ios 4.5.4
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 1.2.1, (and 19 other plugins)

System:

   NodeJS : v10.15.1 (C:\software\nodejs\node.exe)
   npm    : 6.4.1
   OS     : Windows 10 

And here are the plugins installed :

cordova-fabric-plugin 1.1.14-dev "cordova-fabric-plugin"
cordova-plugin-actionsheet 2.3.3 "ActionSheet"
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-camera 4.0.3 "Camera"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-dialogs 2.0.1 "Notification"
cordova-plugin-email-composer 0.8.15 "EmailComposer"
cordova-plugin-facebook4 2.5.0 "Facebook Connect"
cordova-plugin-firebase-analytics 1.1.1 "FirebaseAnalyticsPlugin"
cordova-plugin-geolocation 4.0.1 "Geolocation"
cordova-plugin-google-analytics 1.8.6 "Google Universal Analytics Plugin"
cordova-plugin-googleplus 5.3.2 "Google SignIn"
cordova-plugin-inappbrowser 3.0.0 "InAppBrowser"
cordova-plugin-ionic-keyboard 2.1.3 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 1.2.1 "cordova-plugin-ionic-webview"
cordova-plugin-network-information 2.0.1 "Network Information"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova-plugin-x-socialsharing 5.4.4 "SocialSharing"
cordova-support-android-plugin 1.0.1 "cordova-support-android-plugin"
cordova-support-google-services 1.3.1 "cordova-support-google-services"
es6-promise-plugin 4.2.2 "Promise"
onesignal-cordova-plugin 2.4.6 "OneSignal Push Notifications"
sentry-cordova 0.13.1 "Sentry"
uk.co.workingedge.phonegap.plugin.launchnavigator 4.2.2 "Launch Navigator" 

Thank you for any advices you may have

Aghamyr commented 5 years ago

It seems I finally found where the issue is coming from, I'll try my best to be clear : Apparently the idToken returned by googlePlus.login() method is differrent in the sense that both "azp" and "aud" values are the iOS client id in iOS case but in Android case the "azp" contains the Android client id and the "aud" the web client id. https://developers.google.com/identity/protocols/OpenIDConnect

So the problem appears on my API once I check the google client id it contains the iOS one instead of the web one and it fails the check. So I guess it's a google librairy problem on my API but I've got no idea why it's not working properly

Aghamyr commented 5 years ago

I found out the answer

Apparently for iOS if you don't add the option 'offline' : 'true' when calling the google login it doesn't use the webClientID you specified. Not sure why it does that for iOS and not for Android though

It's in GooglePlus.m :

NSString* serverClientId = options[@"webClientID"];
...
if (serverClientId != nil && offline) {
    signIn.serverClientID = serverClientId;
}

I'm still interested into why the different behavior for iOS and Android or if it's a bug, but hopefully this will help someone else someday