Maintaining Secret key and Access Token for JWT in Express and NodeJS with Facebook in Rest API Maintaining Secret key and Access Token for JWT in Express and NodeJS with Facebook in Rest API express express

Maintaining Secret key and Access Token for JWT in Express and NodeJS with Facebook in Rest API


Ad 1. You do not have to store the JWT in the database. User ID can be part of the payload, therefore there's no need for it.

Ad 2. It's a common practice for the server side app to use one secret key for generating all JWT.

Ad 3. Check if token has expired on each request to your API and disallow access if the token has expired, return 401 status code. Client app should prompt user for credentials and request new JWT. If you want to avoid users re-submitting the credentials you can issue a refresh token that later can be used to generate new JWT.

JWT refresh token flow

http://bitoftech.net/2014/07/16/enable-oauth-refresh-tokens-angularjs-app-using-asp-net-web-api-2-owin/