Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Simple Authentication for SPA & Mobile API

Simple Authentication for SPA & Mobile API

How to use PHP Sessions to simplify authentication for APIs and Single Page Applications without violation the stateless principle for RestFul webservices.

Ricardo Coelho

July 08, 2015
Tweet

More Decks by Ricardo Coelho

Other Decks in Programming

Transcript

  1. Spot the difference… POST /endpoint HTTP/1.1 Host: server.com Accept: application/json…

    Accept-Encoding: gzip, deflate Content-Type: application/json Connection: keep-alive { “token”: “SOME_TOKEN”, “info”: “some info” } POST /endpoint HTTP/1.1 Host: server.com Accept: application/json… Accept-Encoding: gzip, deflate Content-Type: application/json Cookie: PHPSESSID=SOME_ID Connection: keep-alive { “info”: “some info” }
  2. Create a resource Whenever you need to keep business data

    or large amount of information on the server.
  3. Create a resource Associate it with the user id stored

    in the session and avoid passing on every request, saving data plans on mobile.