AngularJS or SPA with JWT - expiry and refresh

前端 未结 3 1829
粉色の甜心
粉色の甜心 2021-02-03 10:25

I understand the flow of JWT and a single page application in terms of login and JWT issuance. However, if the JWT has a baked in expiry, AND the server isn\'t issuing a new JW

3条回答
  •  旧时难觅i
    2021-02-03 10:52

    Renewing the token every 15 minutes (if it lives for 30) works if you don't have another restriction in your server in which you need to check for 1 hour inactivity to log the user out. If you just want this short lived JWT and keep on updating it, it'd work.

    I think one of the big advantages of using JWT is to actually NOT need a server session and therefore not use the JTI. That way, you don't need syncing at all so that'd be the approach I'd recommend you following.

    If you want to forcibly logout the user if he's inactive, just set a JWT with an expiration in one hour. Have a $interval which every ~50 minutes it automatically gets a new JWT based on the old one IF there was at least one operation done in the last 50 minutes (You could have a request interceptor that just counts requests to check if he's active) and that's it.

    That way you don't have to save JTI in DB, you don't have to have a server session and it's not a much worse approach than the other one.

    What do you think?

提交回复
热议问题