JWT (JSON Web Token) automatic prolongation of expiration

后端 未结 12 2051
一向
一向 2020-11-22 10:56

I would like to implement JWT-based authentication to our new REST API. But since the expiration is set in the token, is it possible to automatically prolong it? I don\'t wa

12条回答
  •  失恋的感觉
    2020-11-22 11:32

    Below are the steps to do revoke your JWT access token:

    1) When you do login, send 2 tokens (Access token, Refresh token) in response to client .
    2) Access token will have less expiry time and Refresh will have long expiry time .
    3) Client (Front end) will store refresh token in his local storage and access token in cookies.
    4) Client will use access token for calling apis. But when it expires, pick the refresh token from local storage and call auth server api to get the new token.
    5) Your auth server will have an api exposed which will accept refresh token and checks for its validity and return a new access token.
    6) Once refresh token is expired, User will be logged out.

    Please let me know if you need more details , I can share the code (Java + Spring boot) as well.

提交回复
热议问题