SPA best practices for authentication and session management

When building SPA style applications using frameworks like Angular, Ember, React, etc. what do people believe to be some best practices for authentication and session management? I can think of a couple of ways of considering approaching the problem.

  1. Treat it no differently than authentication with a regular web application assuming the API and and UI have the same origin domain.

    This would likely involve having a session cookie, server side session storage and probably some session API endpoint that the authenticated web UI can hit to get current user information to help with personalization or possibly even determining roles/abilities on the client side. The server would still enforce rules protecting access to data of course, the UI would just use this information to customize the experience.

  2. Treat it like any third-party client using a public API and authenticate with some sort of token system similar to OAuth. This token mechanism would used by the client UI to authenticate each and every request made to the server API.

I’m not really much of an expert here but #1 seems to be completely sufficient for the vast majority of cases, but I’d really like to hear some more experienced opinions.

3 Answers
3

Leave a Comment