I would like to know if what I've done so far is a sound way of authenticating/renewing the token and if there are any flaws or vulnerabilities that I should be aware of as I tried to limit database interaction to nil. Here goes.
- The user authenticates via normal Username/password or via Facebook
- The PHP backend generates a token with an expiration time of 30 minutes and sends it to the angularjs client
- The JWT token gets stored in $localStorage
- The JWT token is injected, with the help of an interceptor, in every request header
- All the Slim routes that need authentication check the sent token with the help of a middleware.
- If the token is invalid (expired, has been tampered with, is not suitable for that particular role), Slim will respond with a 401/403 error.
- An angular service checks every minute if the token is about to expire
- If the token is about to expire (5 to 1 minutes left), the service posts the old token to another API endpoint.
- The API endpoint checks the validity of the token and responds with a new one with an expiry time of +30 mins.
- The polling service I mentioned before replaces the old token in $localStorage.
- Rinse and repeat.
NB: SSL will be implemented in production
Bounty awarded to @Valdas as he was the only one who actually answered