ngx-cordova-oauth icon indicating copy to clipboard operation
ngx-cordova-oauth copied to clipboard

Google OAuth no longer works due to restrictions

Open mircowidmer opened this issue 8 years ago • 8 comments

I tried using Google OAuth similar to this description: https://www.thepolyglotdeveloper.com/2016/01/use-ng2-cordova-oauth-for-all-your-ionic-2-oauth-needs Instead of using Facebook, I tried Google and registered my app in the developer console. But it seems that it is not possible anymore to use Google OAuth embedded in a web view (https://developers.googleblog.com/2016/08/modernizing-oauth-interactions-in-native-apps.html)

Is this a known issue and is there an other way to use Google as an identity provider?

mircowidmer avatar Jan 05 '17 22:01 mircowidmer

I guess it is not possible to use it with Google like described in the README of https://github.com/nraboy/ng-cordova-oauth. Then I would suggest to remove the option completely.

mircowidmer avatar Jan 05 '17 22:01 mircowidmer

@nraboy @mircowidmer it's possible to implement support for Google. Obviously it requires more infrastructure setup.

By the way, there is also OauthBrowser adapter in this lib which currently supports Google ;) Cordova adapter doesn't support. In my application I use https://github.com/EddyVerbruggen/cordova-plugin-safariviewcontroller . I implemented OauthSafariController which does the same but opens urls in SafariController/Chrome tabs.

Then you need to configure Applinks/Universal links for your application (or at least custom app scheme) and put URL to your website in Google in allowed redirect urls.

So, when user authenticate via Google oauth, Google server will redirect user to your site. In case of configured Applinks/Universal links Safari VC will open your application and you can route this to whatever you want (I personally just emitting even in App bus). OauthSafariController listens for this event and closes Safari. Alternatevly you can use custom app scheme and specify http://my.site.com?mobile=1&provider=google as your redirect_uri for Google Oauth. Eventually in my site added logic like this:

  <head>
    <script type="text/javascript">
       if (location.pathname.indexOf('/login') === 0 && location.search.indexOf('?mobile=1') === 0) {
         window.location = 'myappscheme://' + location.pathname + location.search
       }
    </script>
  </head>

Afterwards user is successfully logged in.

Maybe a bit later I will do PR but this will add 2 additional dependencies Ionic Deeplinks and Cordova Safari View Controller

stalniy avatar Jul 12 '17 05:07 stalniy

Also there is #60 which is sitting there to partially fix issue with google (actually allows to put custom query params in redirect uri). I tested this approach on facebook provider and it works great :)

stalniy avatar Jul 12 '17 06:07 stalniy

Please check #61 which implements support for Safari View Controller and Google oauth. Tested facebook oauth on Android and iOS, works as expected

stalniy avatar Jul 12 '17 19:07 stalniy

Merged into the development branch.

Can I get some people to test the development branch? After I will merge it to a release build.

nraboy avatar Aug 04 '17 22:08 nraboy

Is there a way to test it within an app? I tried to install it via npm

npm install nraboy/ng2-cordova-oauth#development --save

but then I'm missing a bunch of folders and files. Here's what I get. Let me know if I'm just overlooking something. screen shot 2017-08-08 at 2 55 32 pm

sageknives avatar Aug 08 '17 21:08 sageknives

You'll need to clone the project on GitHub, build it with the TypeScript compiler, then add it to your Cordova project from your local machine.

The compiled files don't reside on GitHub, and the development branches are not checked into NPM.

Best,

nraboy avatar Aug 13 '17 14:08 nraboy

Hi.

I get many errors trying to compile:

[email protected] build.system /home/jcarlos/Documentos/proyectos_jc/ionic/ngx-cordova-oauth-development tsc --outFile ng2-cordova-oauth.system.js --module system

src/platform/safari.ts(32,26): error TS1180: Property destructuring pattern expected. src/platform/safari.ts(32,42): error TS1005: ',' expected. src/platform/safari.ts(32,44): error TS1005: ',' expected. src/platform/safari.ts(33,9): error TS1005: ',' expected. src/platform/safari.ts(39,42): error TS1136: Property assignment expected. src/platform/safari.ts(39,58): error TS1005: ',' expected. src/platform/safari.ts(39,59): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. src/platform/safari.ts(39,61): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. src/platform/safari.ts(42,10): error TS1005: ';' expected. src/platform/safari.ts(43,7): error TS1128: Declaration or statement expected. src/platform/safari.ts(43,8): error TS1128: Declaration or statement expected. src/platform/safari.ts(44,5): error TS1128: Declaration or statement expected. src/platform/safari.ts(44,6): error TS1128: Declaration or statement expected. src/platform/safari.ts(45,3): error TS1128: Declaration or statement expected. src/platform/safari.ts(47,3): error TS1128: Declaration or statement expected. src/platform/safari.ts(47,37): error TS1005: ';' expected. src/platform/safari.ts(58,3): error TS1128: Declaration or statement expected. src/platform/safari.ts(58,41): error TS1005: ';' expected. src/platform/safari.ts(66,1): error TS1128: Declaration or statement expected.

Previously I've had to add this line on tsconfig.json

    "src/platform/browser.ts",
    "src/platform/cordova.ts",
    "src/platform/safari.ts", <<---------------- this one.
    "node_modules/typescript/lib/lib.es6.d.ts"

regards

a930334 avatar Mar 02 '18 20:03 a930334