jpadilla / django-rest-framework-jwt

JSON Web Token Authentication support for Django REST Framework
http://jpadilla.github.io/django-rest-framework-jwt/
MIT License
3.19k stars 648 forks source link

Exposing JWT Token expiration #448

Open superandrew opened 6 years ago

superandrew commented 6 years ago

I searched the documentation for a setting that allows to expose the token expiration. I implemented a response handler, but i don't know where to take the expiration date.

Something like:

def jwt_response_payload_handler(token, user=None, request=None):
    return {
        'token': token,
        'expiration':"12312312312312"
    }

Thanks

superandrew commented 6 years ago

alright so this is my implementation: import datetime from rest_framework_jwt.settings import api_settings

def jwt_response_payload_handler(token, user=None, request=None):

    return {
        'token': token,
        'exp': datetime.datetime.utcnow() + api_settings.JWT_EXPIRATION_DELTA
    }

where is that date checked? I checked the db but found no tables where this information is stored. Sorry but I'm not finding this on the docs.

cyberbudy commented 5 years ago

Actually, it's a part of a token. You can check jwt_decode_handler method where token is decoded by jwt library. Also that library performs multiple checks, such as checking expiry time.