title: Facebook login with passport.js, sails.js API and ember.js
body: <p>I'm setting up this Sails project where I use PassportJS, via <a href="https://github.com/kasperisager/sails-generate-auth" rel="nofollow noreferrer">sails-generate-auth</a>, and JWTs - using <a href="https://github.com/tarlepp/angular-sailsjs-boilerplate" rel="nofollow noreferrer">this</a> 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?</p>
  
  <p>I'm able to successfully login to Facebook via passport js using an AJAX GET to <code>/auth/facebook</code> like so</p>
  
  <pre><code>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);
  });
  </code></pre>
  
  <p>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. </p>
  
  <p>Is there any way to do what I'm trying to do? Or should I just redirect to the front-end app from <code>passport.callback</code>?</p>
  
  <h1>Update</h1>
  
  <p>After a bit more searching, I came across this answer: <a href="https://stackoverflow.com/questions/14572600/passport-js-restful-auth?rq=1#answer-16781555">passport.js RESTful auth</a></p>
  
  <p>It seems that I cannot achieve what I want since Facebook only exposes a redirect-based authentication, not an async or JSON one. Good to know...mark as duplicate if you'd like.</p>