Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to set tokens invalid ? #143

Closed
igor-yamshchykov opened this issue Nov 24, 2015 · 6 comments
Closed

Is it possible to set tokens invalid ? #143

igor-yamshchykov opened this issue Nov 24, 2015 · 6 comments

Comments

@igor-yamshchykov
Copy link

For instance someone steals user token (no matter how) and user requests to set those invalid.

the tokens are always created with users id, is it possible to set the tokens created previously invalid according to specific user id ?

@willfarrell
Copy link

You would have to have a check in your code to compare the user and exp or iat in the token to a table where you store the user and timestamp. You'll need to use your expiresInSeconds depending on the approach you want to take.

If you're always passing in the user_id with the token you could use separate keys for each user, then just replace the key when you want to void the existing ones.

@igor-yamshchykov
Copy link
Author

Thanks, but tracking is not a problem actually, is there a function or something to set the token expired ?
Something like jwt.setExpired(token, secretOrPublicKey) ?

@willfarrell
Copy link

Not possible doing it how you envision it working. The token has the expiry date encrypted inside of it. Since you can't force the client to replace their token, using something like jwt.setExpired(token, secretOrPublicKey) will not work. That is why tracking when users has expired tokens or replacing their secret key are the two main options you have for expiring a token early.

@igor-yamshchykov
Copy link
Author

Thanks, I think I'll use the approach with user secret keys for token.

@imakshath
Copy link

Hi, I have to logout the session while user click 'logout' link. In this case i need to expire the token so what would be the solution for this?

@jfromaniello
Copy link
Member

The solution is to keep a blacklist where the key is either the full token or the JTI (json webtoken id).

The blacklist can have a TTL (time-to-live) based on the exp field. (Once the token is expired it can be removed from the blacklist.)

More details in this blogpost:

https://auth0.com/blog/2015/03/10/blacklist-json-web-token-api-keys/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants