dimanche 19 avril 2015

Facebook login with passport.js, sails.js API and ember.js

I'm setting up this Sails project where I use PassportJS, via sails-generate-auth, and JWTs - using this as a guide - to login. I'm trying to decouple the api from the Ember app as much as I can so I can use the same API for iOS, etc. Since passport uses callbacks to handle Facebook auth, how can I login via AJAX?


I'm able to successfully login to Facebook via passport js using an AJAX GET to /auth/facebook like so



var url = config.api + '/auth/facebook'
var controller = this;
Ember.$.get( url, function ( data ) {
// This is never called because Facebook redirects
localStorage.private_token = data.token;
controller.transitionToRoute('profile', data.user);
});


but then when Facebook redirects, it goes back to the API, not the frontend app. But if I configure the backend to redirect to the front end app after the callback, I have a dependency on the front end app that I want to avoid. I've never done Facebook auth before but I've used API tokens for a while now.


Is there any way to do what I'm trying to do? Or should I just redirect to the front-end app from passport.callback?


Aucun commentaire:

Enregistrer un commentaire