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 on device! #331

Closed clubery closed 7 years ago

clubery commented 7 years ago

This plugin does not seem to work. I have seen many examples explaining that this will only work on a real device. However, I have tried this on both the simulator and a real device and both result in the error "Cannot authenticate via a web browser". There are also many examples around the web with this same issue yet there doesn't seem to be any solution anywhere.

I am using Angular JS 1.6, Ionic 1.7.6 and Cordova 7.0.2

My Angular module looks like this:

( function () {
    'use strict';

    angular
        .module( 'app', [
            'mymods',
            'ionic',
            'ngCordova',
            'ngCordovaOauth'
        ] )

...

My app run function looks like this:

( function () {
    'use strict';

    angular
        .module( 'app' )
        .run( runFunction );

    /* @ngInject */
    function runFunction( $rootScope, $state, $ionicPlatform ) {
        $ionicPlatform.ready( function () {
            if ( window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard ) {
                cordova.plugins.Keyboard.hideKeyboardAccessoryBar( true );
                cordova.plugins.Keyboard.disableScroll( true );

            }
            if ( window.StatusBar ) {
                StatusBar.styleDefault();
            }
        } );

...

And my controller looks like this:

( function () {
    'use strict';

    angular
        .module( 'app' )
        .controller( 'LoginController', LoginController );

    /* @ngInject */
    function LoginController( $ionicPlatform, $window, $cordovaOauth, $log, $scope ) {
        var vm = this;
        vm.doLogin = function () {

            var appID = "XXXXXXXXXXXXXXXX";
            var redirectURL = "http://localhost/callback";

            $cordovaOauth.facebook( appID, [ "email" ], {
                    redirect_uri: redirectURL
                } )
                .then( function ( result ) {
                        var access_token = result.access_token;
                        $log.log( "result: ", result );
                        $http.get( "https://graph.facebook.com/v2.2/me", {
                                params: {
                                    access_token: access_token,
                                    fields: "name, email",
                                    format: "json"
                                }
                            } )
                            .then( function ( user ) {
                                //     alert(JSON.stringify(user));
                                //IonicLogin.socialLogin( user.data.email, user.data.id ); // USING ID TO GENERATE A HASH PASSWORD
                            } )
                    },
                    function ( error ) {
                        $log.log( "Facebook Login Error: " + error );
                    } );

        };

...

I have tried different combinations of different plugin versions and still no joy. Any help on this issue would be greatly appreciated.

nraboy commented 7 years ago

Are you trying to use Ionic Serve, Ionic Live-Reload, or Ionic View? All of those simulate incorrectly. The binary must be installed and ran to prevent that error.

clubery commented 7 years ago

No I am not using any of those tools, I am building and deploying to the device directly from xcode the standard way and running the application on an iPhone 6 and then debugging using safari.

I also tried https://github.com/nraboy/ng-cordova-facebook-example but this appears to have other issues.

I've also done this in an empty application to make sure its not any of my own dependencies clashing with the code in this library and no joy.

Are there some extra configuration options that need to be specified in xcode? or in the html?

I have spent days trying to figure this out its killing me :(

nraboy commented 7 years ago

Are you trying to use this?:

https://github.com/apache/cordova-plugin-wkwebview-engine

Plugins that affect how Apache Cordova works can also affect how the OAuth plugin works. This is because the InAppBrowser is very particular. If you dig into the source code of this plugin, you'll see how it works. Everything is dependent on the InAppBrowser.

If you need help, I'm available for consulting and education:

https://www.thepolyglotdeveloper.com/hire-me/

Best,

nraboy commented 7 years ago

This information might help as well:

https://github.com/nraboy/ng-cordova-oauth/issues/280

clubery commented 7 years ago

I am not doing any of the above, in fact, I haven't ever heard of the wkwebview component until you mentioned it to me now.

So maybe I need to be clear again, I have created an empty angularjs application that depends on only on ionic, ngcordova and ngcordova0auth.

I create 1 button in this app which is supposed to trigger the code from this library. I have done nothing special and followed the instructions. I then do an ionic platform add iOS and ionic build iOS. Once I have done that I open the project in Xcode and assign the provisioning profiles and then run the application on the device.

This is the basics, like please can you show me a working example of this? A fork anything? Where the right versions of plugins are configured and I can install this on an iOS device and actually make it work.

So far you have suggested that I am doing things incorrectly but this looks as if some configuration steps are either missing or there is a bug in the library.

I have also looked at those links and I am not experiencing those issues. Why doesn't this work out of the box?

In my previous post I pointed to your own repository that has a project using this library which also doesn't work.

So can you check this plugin actually works on an iOS device please and then outline the steps needed to do that?

nraboy commented 7 years ago

I took this animated GIF today (June 19, 2017) using the latest version of Ionic 1 and ngCordovaOauth...

ionic1-facebook-oauth

As you can see it works fine for me on both Android and iOS using a fresh project.

Since I cannot reproduce your issue I am going to close the ticket. If you'd like free help with using the library I encourage you to ask in the Ionic forums or on Stack Overflow. If you'd like paid help from me, you can fill out the form here:

https://www.thepolyglotdeveloper.com/hire-me/

Best,

clubery commented 7 years ago

@nraboy Hey that really sucks man. I have a genuine issue that may actually be with this plugin, instead of investigating you have sent me an animated gif of a screenshot on a totally different operating system in a simulator that doesn't even suffer from the same issues and then ask me to pay you to fix issues with your own plugin. Sorry that's not a good way to get business, I could understand if I was asking you for an enhancement. None of those environment characteristics you tested with are even close to what I described in my previous comments so, no, there is no possible way you could reproduce my issue with those parameters.

Maybe you could release the code of that animated gif onto a public repo and I could test it myself, but since its just an animated gif on a different OS you have just led me to a dead end.

nraboy commented 7 years ago

I'm not trying to be rude or make you angry. This is an open source project. The community contributes to it and the community supports it. Supporting everyones specific needs easily becomes a full time job which is why I'm directing you to a forum board or offering you paid support. I'm not forcing you pay me. It is only one of many options.

https://github.com/nraboy/ng-cordova-oauth#support

I created the project based on the README. No tricks were involved.

If you don't like how open source works, I encourage you to find a closed sourced plugin.