lynndylanhurley / ng-token-auth

Token based authentication module for angular.js.
Do What The F*ck You Want To Public License
1.8k stars 233 forks source link

Ionic/Android 'requestCredentials is not defined' #311

Open ryan-on-rails opened 8 years ago

ryan-on-rails commented 8 years ago

Good morning all,

I've been banging my head against a wall trying to figure out this issue so I come to you, who have hopefully dealt with something like this and are far smarter than I.

I'm building an ionic app with a rails api backend. Implemented ng-token-auth/devise-token-auth and everything works smoothly for regular login as well as social media login when running the app on my local machine via ionic serve

Once I build the code and attempt to test on my android tablet via ionic run android, the app loads normally, I click one of the social media login buttons and the inAppBroswer opens per my configuration to the social media login page. I enter my credentials, the rails api is hits on the OmniauthCallbacksController successfully, returning a 200.

Then the browser hangs on a white page and I receive this in the android logs: "Uncaught ReferenceError: requestCredentials is not defined"

I've traced this down to this particular place in the ng-token-auth code:

            handleLoadStop: function(authWindow) {
              _this = this;
              return authWindow.executeScript({
                //BREAKS HERE
                code: 'requestCredentials()'
              }, function(response) {
                var data, ev;
                data = response[0];
                if (data) {
                  ev = new Event('message');
                  ev.data = data;
                  _this.cancelOmniauthInAppBrowserListeners();
                  $window.dispatchEvent(ev);
                  _this.initDfd();
                  return authWindow.close();
                }
              });
            },

I've tried to implement the various solutions in previous issues #90 and #141 to no avail. Any help that could be provided would be greatly appreciated!

aL3xa commented 8 years ago

I can confirm bug on Android using cordova v6.3.1, with ng-token-auth commit ebfdf59 and devise_token_auth commit 536911c.

@RyanMilstead1 did you manage to find fix/workaround in the meantime?

FTR, auth process works just fine on non-cordova projects, both with sameWindow and newWindow omniauthWindowType option.

ryan-on-rails commented 8 years ago

@aL3xa Nope this is still an outstanding bug on my project :( I'll update here if I find a fix for it!