nraboy / ng-cordova-oauth

AngularJS oauth library for use with Apache Cordova projects
https://www.thepolyglotdeveloper.com
MIT License
456 stars 199 forks source link

"Cannot authenticate via a web browser" #332

Closed mojocakes closed 7 years ago

mojocakes commented 7 years ago

Hi, when using the following code I receive the error message "Cannot authenticate via a web browser".

$cordovaOauth.facebook(fbID, ['public_profile', 'email'], options)
.then(function (result) {
    alert('Facebook signin' + JSON.stringify(result));
}, function (error) {
    alert('Facebook error' + JSON.stringify(error));
});

This happens both in the iOS simulator and on an iPhone 6 device.

I have set up the cordova whitelist plugin and enabled access to the relevant oauth urls. My facebook app has "http://localhost/callback" set as the redirect URI. I've also enabled "Embedded Browser OAuth Login" in the facebook app. Is there something else I might be missing?

nraboy commented 7 years ago

Hey @mojocakes,

Does anything from https://github.com/nraboy/ng-cordova-oauth/issues/331 apply to you? The user was having a problem like this, but it is his environment / deployment strategy.

If you crack open the library source code, you might run into these lines:

https://github.com/nraboy/ng-cordova-oauth/blob/master/src/oauth.facebook.js#L20-L21

The first checks to see if you're using Apache Cordova in application format rather than trying to serve it using things like Ionic Serve, Live-Reload, Ionic View, etc. The second checks to make sure you have the InAppBrowser plugin installed.

Using plugins like WKWebView and CrossWalk will disrupt how web views work within the application. This will also cause the library to fail if you're using them.

In short though, the error is not related to how you've configured Facebook, but how your environment is setup and how you're deploying the application.

Best,

mojocakes commented 7 years ago

I've found the issue, for whatever reason cordova.js wasn't being loaded on the page. Thanks for your help @nraboy, linking to the code pointed me in the right direction

nraboy commented 7 years ago

Glad you got it :-)