Skip to content

Commit 89d5b99

Browse files
committed
Fix jwt.exceptions import and handle InvalidKeyError
1 parent 47a35bd commit 89d5b99

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

rest_framework_sso/authentication.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# coding: utf-8
22
from __future__ import absolute_import, unicode_literals
33

4-
import jwt
4+
import jwt.exceptions
55
from django.utils.encoding import smart_text
66
from django.utils.translation import ugettext as _
77
from rest_framework import exceptions
@@ -47,13 +47,16 @@ def authenticate(self, request):
4747

4848
try:
4949
payload = decode_jwt_token(token=token)
50-
except jwt.ExpiredSignature:
50+
except jwt.exceptions.ExpiredSignature:
5151
msg = _('Signature has expired.')
5252
raise exceptions.AuthenticationFailed(msg)
53-
except jwt.DecodeError:
53+
except jwt.exceptions.DecodeError:
5454
msg = _('Error decoding signature.')
5555
raise exceptions.AuthenticationFailed(msg)
56-
except jwt.InvalidTokenError:
56+
except jwt.exceptions.InvalidKeyError:
57+
msg = _('Unauthorized token signing key.')
58+
raise exceptions.AuthenticationFailed(msg)
59+
except jwt.exceptions.InvalidTokenError:
5760
raise exceptions.AuthenticationFailed()
5861

5962
return self.authenticate_credentials(payload=payload)

0 commit comments

Comments
 (0)