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

[Question] Revoking tokens on refresh #65

Open
ultratin opened this issue Aug 31, 2021 · 6 comments
Open

[Question] Revoking tokens on refresh #65

ultratin opened this issue Aug 31, 2021 · 6 comments

Comments

@ultratin
Copy link

Is there anyway to tokens programmatically? Right now tokens are revoked based with the following code

    Authorize.jwt_required()

    jti = Authorize.get_raw_jwt()['jti']
    redis_conn.setex(jti, settings.access_expires,'true')

The problem lies with Authorize.get_raw_jwt which only allows revoking of the token that is required.
My use case is that on refresh, I would like to refresh both access_token and refresh_token. Is there anyway to accomplish that?

@ultratin
Copy link
Author

Looks like I can get the tokens from the cookies straight from the Request object and access their jti with Authorize.get_jti and revoke the tokens from there. Would that be the only way? Would be great there was a get_token_from_cookie(name="access") method that I can call to simplify things a little bit more

@SelfhostedPro
Copy link

Why are you revoking the access token on refresh? The refresh endpoint should only be getting hit if the access token is already invalid.

@ultratin
Copy link
Author

ultratin commented Sep 1, 2021

I'm not super familiar with the subject but let's say the refresh last for 7 days, the user would be logged out no matter what after 7 days right? What should I be doing if I wanted to extend the refresh past the expiry if the user stays logged in?

@SelfhostedPro
Copy link

You can't extend the refresh past the expiration. You can change the expiration time though. It's automatically invalidated once it's expired.

@ultratin
Copy link
Author

ultratin commented Sep 2, 2021

yes so I'm planning to refresh the refresh token as well, Is that a bad idea?

@mccarreon
Copy link

yes so I'm planning to refresh the refresh token as well, Is that a bad idea?

Found this stackoverflow post in my research on jwt auth.

I think you're trying to implement what's called refresh token rotation, where you refresh the refresh token every time it's used.

Be aware that this can lead to an attacker intercepting the RT, and having infinite uses if the user never returns to the app.

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

3 participants