djangorestframework-simplejwt
djangorestframework-simplejwt copied to clipboard
How to create never expiring AccessToken
Is there any way to create a never expiring AccessToken by configuring settings which will not expire just like some API Key?
Actually, I need to create some API Key using this library, so that I can verify views like normal tokens but it won't expire until someone forcefully disable it.
I can't find set variable way.
but you can override "AUTH_TOKEN_CLASSES": ("rest_framework_simplejwt.tokens.AccessToken",), in settings and write your own AccessToken class, and over ride the behaviour of check_exp method. for ex:
class MyAccessToken(AccessToken):
def check_exp(
self, claim: str = "exp", current_time: Optional[datetime] = None
) -> None:
pass
Maybe a better way is using Constance, and change this behaviour in realtime.
class MyAccessToken(AccessToken):
def check_exp(
self, claim: str = "exp", current_time: Optional[datetime] = None
) -> None:
if settings.get('EXPIRABLE_TOKENS'):
super().check_exp(claim, current_time)