sahat / satellizer

Token-based AngularJS Authentication
https://satellizer-sahat.rhcloud.com
MIT License
7.85k stars 1.13k forks source link

disallowed_useragent on iOS. Google+ no longer supports embedded web-views -> inAppBrowser #1029

Open deliverymanager opened 7 years ago

deliverymanager commented 7 years ago

I have recently created a new google plus project/key and when I tried to make a login from my Ionic/iOS app, I got the following error: disallowed_useragent The explaination of it is below. https://developers.googleblog.com/2016/08/modernizing-oauth-interactions-in-native-apps.html

That probably means that we can no longer use the inAppBrowser cordova plugin? How will satellizer work from now on?

wmalevski commented 7 years ago

+1

Is there some solution about this?

akshayjoshi999 commented 7 years ago

waiting for solution or temporary work around for this. stuck with this have a pending release

gigmaps commented 7 years ago

possible fix by changing this line from _blank to _system https://github.com/sahat/satellizer/blob/master/src/popup.ts#L49

as per https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-inappbrowser/#cordovainappbrowseropen

...haven't tried it yet.

chr4ss1 commented 7 years ago

gigmaps solution did not work.

I didn't find solution that I liked, however, there is a way to set the user agent string in config.xml by using

OverrideUserAgent key and some arbitrary value which bypasses Google's detection, and will successfully be able to log in.

The problems with this approach though are:

1) confusing documentation: https://cordova.apache.org/docs/en/latest/config_ref/index.html OverrideUserAgent says it's only supported on Android, however it worked on iOS for me as well.

2) ionic.bundle.js has dependency on the user agent, so it can't be anything random. If you put user agent as "Mozilla Firefox", you'll bypass google, but then ionic.Platform.isIOS() etc stop working.

at the end of the day, I wanted stable and clear solution, so I ended up not working around this and decided to rewrite it using native stuff.

chr4ss1 commented 7 years ago

small edit:

I found a better solution, I still ended up using native solution, however it integrated quite well with Satellizer so I didn't need to do anything hackish IMO. The way it works is that I inject SatellizerPopup, and check if it's trying to open google authentication modal, if yes, I'll show the native popup instead.

This is just part of angularJS run(), note that you probably have to modify it quite a bit (the logic stays the same), but you probably don't use ES6 the way I do.

export default function ($q, SatellizerPopup, GOOGLE_WEBCLIENT_ID) {

    const originalPopupOpenFunc = SatellizerPopup.open;

    SatellizerPopup.open = function (url, name, popupOptions, redirectUri, dontPoll) {
        if (name === 'google') {
            const deferred = $q.defer();
            const googlePlusSettings = {
                webClientId: GOOGLE_WEBCLIENT_ID, // use whatever variable you have
                offline: true
            };

            const nativeLoginSuccess = (response) => {
                deferred.resolve({
                    clientId: googlePlusSettings.webClientId,
                    code: response.serverAuthCode,
                    redirectUri
                });
            };

            const loginNatively = () => window.plugins.googleplus.login(googlePlusSettings,    nativeLoginSuccess, deferred.reject);

            window.plugins.googleplus.logout(loginNatively, loginNatively);
            return deferred.promise;
        }
        return originalPopupOpenFunc.apply(this, arguments);
    };
}
persnoid commented 7 years ago

@ChrisEelmaa: how can I use your solution with ionic 1? I have difficulty to integrate your solution in my project which is written in angularJs an ionic 1.

knvpk commented 7 years ago

So what is the final conclusion for this thread?

knvpk commented 7 years ago

Yesterday I googled and found a way finally. Here is my process

Steps:

  1. installed the chrome custom tabs Cordova plugin.

  2. Created by own URL and opening in a custom tab.

    1. redirecting the intermediate code to my server URL.

    2. In the server I'm redirecting to app by using the custom URL scheme (in my case elivio://registration/{code})

    3. In the app im handling the deeplink and getting the token and then again sending to server for getting the original JWT login token.

The above process is checked only for Android

knvpk commented 7 years ago

Indirectly I'm not using this plugin only when the provider is Google.