angularjs - Firebase $onAuth has wrong authData after $authWithOAuthRedirect from Facebook -


i trying authenticate users of firebase (angularfire) app facebook login.

everything works expected when authenticate pop-up window, support many browsers possible (chrome on ios doesn't support pop-ups, e.g.) want fallback authenticating redirect ($authwithoauthredirect).

i have confirmed setting in facebook correct (my app id , secret, e.g.) when redirected app after facebook authenticating redirect, $onauth fires don't have facebook authdata.

instead, have anonymous authdata. bit of background; users authenticated anonymously if not otherwise authenticated (with facebook, in e.g.).

i can't see find why - user should authenticated facebook, , have facebook authdata.

excepts of code below context:

triggered when user clicks login button

function login () {     firebaseauth         .$authwithoauthredirect('facebook', function (error) {             if (error) {                 console.log(error);             }         }); } 

$onauth (inside angular app's run)

function run ($rootscope, firebaseauth, sessionstore) {     $rootscope         .$on('$routechangeerror', function (event, next, prev, error) {             if (error === 'auth_required') {                 console.log(error);             }         });      $rootscope         .$on('$routechangesuccess', function (event, current, prev) {             $rootscope.title = current.$$route.title;         });      firebaseauth         .$onauth(onauth);      function onauth (authdata) {         console.log(authdata);     } } 

route resolver otherwise anonymously authenticates users

function sessionstate ($q, firebaseauth) {     var deferred = $q.defer();      firebaseauth         .$requireauth()         .then(deferred.resolve, guest);      return deferred.promise;      function guest () {         firebaseauth             .$authanonymously()             .then(deferred.resolve, rejected);     }      function rejected () {         deferred.reject('auth_required');     } } 

the route resolver (sessionstate) checks see if user authenticated already, , if not, tries anonymously authenticate them.

after facebook authentication redirect, user authenticated, , therefore not need anonymously authenticated.

but, appears are? $onauth logs authdata console, , anonymous.

any appreciated! sure has route resolver, pop-up authentication works fine (the route resolved).

edit: tried removing route resolver in case causing issue, made no difference. user 'unauthenticated' instead of being either authenticated facebook (after $authwithoauthredirect) or anonymously.

update: tried authenticating twitter , redirect transport , have encountered exact same problem. have tried using port 80, instead of port 3000 app being served on locally, no joy.

update: when turn off html5mode mode in app - , routes begin #s - $authwithoauthredirect works perfectly. can assume $authwithoauthredirect not support angularjs's html5mode. can confirm issue, or need change code support html5mode , authwithoauthredirect?

example repo here example repo demonstrating problem: https://github.com/jonathonoates/myapp

look in dist directory - should able download , run app reproduce problem. in scripts/main.js app's js; i've added couple of comments it's pretty self explanatory.

to reproduce problem: click on 'facebook login' button, , you'll redirected facebook authenticate. fb redirect app, here lies problem - won't authenticated, , returned authdata null - you'll see in console

update: when add hashprefix in html5mode e.g.

$locationprovider     .html5mode(true)     .hashprefix('!'); 

the app works expect - authenticating facebook , redirect transport works.

couple of niggles though:

  1. the url has #%3f appended it, , available/visible in browser's history.
  2. this rewrite urls #! in browsers not support history.pushstate (html5mode), , less advanced search engines might html fragment because of 'hashbang'.

i'll highjacking url upon being redirected facebook instead of using hashprefix. in url there __firebase_request_key may significant e.g.

http://localhost:3000/#%3f&__firebase_request_key= 

it looks indeed incompatibility between firebase , angularjs's html5mode suspected. @ end of redirect flow, firebase leaving url "http://.../#?", , angular apparently doesn't did redirect "http://.../" redirect interrupts firebase (the page reloads while we're trying auth against backend) , unable complete authentication process.

i've made experimental fix ensures revert url http://.../#" @ end of redirect flow, angular happy with, preventing problematic redirect. can grab here if like: https://mike-shared.firebaseapp.com/firebase.js

i'll make sure fix gets next version of js client. can keep eye on our changelog see when released.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -