Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google OAuth no longer works due to restrictions #48

Open
mircowidmer opened this issue Jan 5, 2017 · 8 comments
Open

Google OAuth no longer works due to restrictions #48

mircowidmer opened this issue Jan 5, 2017 · 8 comments

Comments

@mircowidmer
Copy link

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
Copy link
Author

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.

@stalniy
Copy link

stalniy commented Jul 12, 2017

@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
Copy link

stalniy commented Jul 12, 2017

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
Copy link

stalniy commented Jul 12, 2017

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

@nraboy
Copy link
Owner

nraboy commented Aug 4, 2017

Merged into the development branch.

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

@sageknives
Copy link

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

@nraboy
Copy link
Owner

nraboy commented Aug 13, 2017

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,

@a930334
Copy link

a930334 commented Mar 2, 2018

Hi.

I get many errors trying to compile:

ng2-cordova-oauth@0.0.8 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants