JWT (JSON Web Token) automatic prolongation of expiration

后端 未结 12 2220
一向
一向 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:13

    An alternative solution for invalidating JWTs, without any additional secure storage on the backend, is to implement a new jwt_version integer column on the users table. If the user wishes to log out or expire existing tokens, they simply increment the jwt_version field.

    When generating a new JWT, encode the jwt_version into the JWT payload, optionally incrementing the value beforehand if the new JWT should replace all others.

    When validating the JWT, the jwt_version field is compared alongside the user_id and authorisation is granted only if it matches.

提交回复
热议问题