Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

add JWT_EXPIRATION_DELTA's judge #480

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions rest_framework_jwt/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,29 @@ def validate(self, attrs):
# Get and check 'orig_iat'
orig_iat = payload.get('orig_iat')

if orig_iat:
# Verify expiration
refresh_limit = api_settings.JWT_REFRESH_EXPIRATION_DELTA
now_timestamp = timegm(datetime.utcnow().utctimetuple())
is_exp = now_timestamp > api_settings.JWT_EXPIRATION_DELTA

if isinstance(refresh_limit, timedelta):
refresh_limit = (refresh_limit.days * 24 * 3600 +
refresh_limit.seconds)
if is_exp:
if orig_iat:
# Verify expiration
refresh_limit = api_settings.JWT_REFRESH_EXPIRATION_DELTA

expiration_timestamp = orig_iat + int(refresh_limit)
now_timestamp = timegm(datetime.utcnow().utctimetuple())
if isinstance(refresh_limit, timedelta):
refresh_limit = (refresh_limit.days * 24 * 3600 +
refresh_limit.seconds)

if now_timestamp > expiration_timestamp:
msg = _('Refresh has expired.')
expiration_timestamp = orig_iat + int(refresh_limit)
now_timestamp = timegm(datetime.utcnow().utctimetuple())

if now_timestamp > expiration_timestamp:
msg = _('Refresh has expired.')
raise serializers.ValidationError(msg)
else:
msg = _('orig_iat field is required.')
raise serializers.ValidationError(msg)
else:
msg = _('orig_iat field is required.')
msg = _('Token has expired.')
raise serializers.ValidationError(msg)

new_payload = jwt_payload_handler(user)
Expand Down