Search code examples
djangodjango-rest-framework-simplejwt

Is there any way to set lifetime of refresh token to infinite in django-rest-framework-simplejwt?


I am using django-rest-framework-simplejwt for authentication for my Django project. I have done some research but could not find a solution for that. In the documentation, the format to set refresh token is in time delta. Is it possible to set the refresh token to not expire at all?


Solution

  • I think this might not be possible, but you can still achieve similar behavior by setting a very large expiration time for refresh tokens. In your Django project settings, you can configure the expiration time for refresh tokens using the SIMPLE_JWT dictionary.

    # in your settings.py
    SIMPLE_JWT = {
        'REFRESH_TOKEN_LIFETIME': timedelta(days=365*100)  # Set to expire in 100 years
    }