I am referencing another SO post that discusses using refresh tokens with JWT.
JWT (JSON Web Token) automatic prolongation of expiration
I have an application wi
I believe for this scenario you could work with the access token alone, making life easier for your clients but keeping the security benefits of a refresh token.
This is how it would work:
When your user logs in with credentials (username/password) you return a short-lived JWT. You also create a db record where you store:
valid
flag (defaults to TRUE)Your client submits the JWT in every request. As long as the JWT hasn't expired,
it has access to the resources. If the JWT expired, you refresh it
behind the scenes and return both the resource and an additional X-JWT
header
with the new JWT.
When the client receives a response with an X-JWT
header, it discards the
old JWT and uses the new one for future requests.
valid
flag is still true, otherwise reject.updatedAt
field in the db record.This design would also give you the option to revoke all tokens for a user (for example, if the user loses his phone or updates his password).
X-JWT
header on responses.