# Refresh token bug in JWT method

**URL:** <https://community.auth0.com/t/refresh-token-bug-in-jwt-method/8110>\
**Category:** Get Help\
**Tags:** jwt, refresh\_token, refresh-tokens\
**Created:** [September 6, 2017, 9:12pm UTC](https://community.auth0.com/t/refresh-token-bug-in-jwt-method/8110 "2017-09-06T21:12:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![derakhshanfar.hossei](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/derakhshanfar.hossei/32/7246_2.png) [@derakhshanfar.hossei](https://community.auth0.com/u/derakhshanfar.hossei)\
**Post date:** [September 6, 2017, 9:12pm UTC](https://community.auth0.com/t/refresh-token-bug-in-jwt-method/8110/1 "2017-09-06T21:12:25Z")

</div>

according to this article [A JWT old for new exchange schema - 简书](http://www.jianshu.com/p/b11accc40ba7)  
one method to secure the JWT is refreshToken:

in center auth server, we maintain a table like this:

```
table auth_tokens(
    user_id,
    jwt_hash,
    expire
)

```

The following is work flow:

User request the login API with phone and we verified it, after that, the auth server send one token, and register the token ( add one row in the table. )

When the token expired, user request the exchange API with the old token. Firstly the auth server validate the old token as normal except expire checking, then create the token hash value, then lookup above table by user id:

- a. If found record and user\_id and jwt\_hash is match, then issue new  
token and update the table.

To use token continuously ,both legal user and hacker need exchange new token continuously, but only one can success, when one fail, both need login again at next exchange time.

So if hacker got the token, it can be used short time, but can’t exchange new one if legal user exchanged new one next time, because the token valid period is short, it is more security.

If there is no hacker, normal user also need exchange new token periodically ,such as every 30 minutes, this is just like login automatically. The extra load is not high and we can adjust expire time for our application.

**but imagine this senario:**

For example, a hacker got the Bob’s token, and he knows Bob is sleep at 1:00 am to 6:00 am,  
So, the hacker can use the toke at night continuously until Bob get up next day and use the application.

one solution is at the night, user should enter user and pass instead of token but this is not good solution in my idea!  
do you know better solution?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 2, 2018, 5:56am UTC](https://community.auth0.com/t/refresh-token-bug-in-jwt-method/8110/2 "2018-03-02T05:56:21Z")

</div>


