I have some questions regarding an API JWT refresh token workflow using Java Spring.
I have this so far:
- User logs in to /users/login - if successful a response with 2 headers is returned Authorization and Refresh. Which contain 2 tokens - one with short 30 mins expiration and one with longer 4 hours expiration.
- He can then access all other endpoints using the Authorization header.
- If at some point accessing an endpoint his token is expired he receives an error (UNAUTHORIZED).
- And has to do a request to /token/refresh with the refresh token he was given.
Questions:
- I have set it up so authorization token has a claim: type=auth and the refresh token has a claim: type=refresh. What is the best way to distinguish the two tokens.
- What should be the error in step 3 (instead of unauthorized) to distinguish it from a request without a valid token
- /token/refresh doesn't ask for authentication currently. Should it?
- Should the /token/refresh endpoint be a POST with header, POST with parameters or a GET with header.