title: SPA (Ember) authentication vs backend
body: <p>I am trying to wrap my head around implementing proper authentication in an SPA with a backend.</p>
  
  <p>I am looking at 2 different frontends:
  1. SPA with Ember.js
  2. Mobile application</p>
  
  <p>I am trying to design a backend that serves both (either in Rails or in Python, have not decided yet). I want the authentication to take place either via Google or Facebook, i.e. I do not need to maintain separate user registrations but I still need to maintain users as I want to be able to 'merge' authentications from Google and Facebook at the end of the day. I also want the backend to be fully stateless for scalability reasons. Also I would prefer to do as much as possible on the client side to spare the load from the backend.</p>
  
  <p>My questions are as follows:</p>
  
  <ol>
  <li><p>I will request an authentication token in the SPA or in the mobile app. Should I convert this to an access token on the server side or on the client side? I need to authorize backend requests and I need to do that statelessly. My idea was to do everything on the frontend side and pass along the access token to each and every backend request, to be validated on the server side as well but I am not sure if this is an efficient approach.</p></li>
  <li><p>I want to be able to merge Google and Facebook authentications, what are the best practices for that? I was planning to maintain an user registry on the server side and check the email addresses coming from the authorized backend requests and merge the users if there is a match in email addresses. What are the best practices and are there any libraries supporting this in Python/Flask or in Ruby or Rails?</p></li>
  </ol>
  
  <p>Thanks!</p>