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

are there plans for djoser to support Refresh Token Rotation? #698

Open
sinisarudan opened this issue Oct 3, 2022 · 2 comments
Open

are there plans for djoser to support Refresh Token Rotation? #698

sinisarudan opened this issue Oct 3, 2022 · 2 comments

Comments

@sinisarudan
Copy link

sinisarudan commented Oct 3, 2022

This quite simple but powerful mechanism would provide more security for SPAs built using djoser and prevent attacks using refresh tokens.
More at:
https://auth0.com/docs/secure/tokens/refresh-tokens/refresh-token-rotation
https://auth0.com/blog/refresh-tokens-what-are-they-and-when-to-use-them/#You-Can-Store-Refresh-Token-In-Local-Storage

Practically it would mean
/jwt/refresh/ (https://djoser.readthedocs.io/en/latest/jwt_endpoints.html)
should return a new refresh token in addition to the new access token,
while in the same invalidating the previous refresh token.

@evanottinger
Copy link

Not a maintainer, but I just came across this issue and wanted to note that you cannot invalidate JWTs. Once they're signed, they're active until they're expired. Effectively, once the refresh token has expired, the user's session has ended and they must authenticate to get a new one. The refresh endpoint generates a new access token because it should expire at more frequent intervals than the refresh token. For example, we might set the refresh token's expiration to 24 hours from when it's signed, whereas an access token might only be valid for five minutes.

For security, the best practice is to store the refresh token in an HTTP Only, Secure cookie. This prevents it from being accessed by malicious JavaScript or transported unencrypted.

@leomorpho
Copy link

I believe you can use Simple JWT with

SIMPLE_JWT = {
    'ACCESS_TOKEN_LIFETIME': timedelta(minutes=1),
    'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
    'ROTATE_REFRESH_TOKENS': True,
}

Source: https://django-rest-framework-simplejwt.readthedocs.io/en/latest/settings.html#rotate-refresh-tokens

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