Skip to content

Commit 72361c2

Browse files
authored
fix pyjwt version (#41)
* fix pyjwt version ref flavors/django-graphql-jwt#242 ref https://stackoverflow.com/questions/65757394/module-jwt-has-no-attribute-expiredsignature * keep recent jwt version and make necessary adjustments * add utf8 encoding in small caps * format with black
1 parent 423a499 commit 72361c2

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/django_cognito_jwt/validator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ def validate(self, token):
6565
issuer=self.pool_url,
6666
algorithms=["RS256"],
6767
)
68-
except (jwt.InvalidTokenError, jwt.ExpiredSignature, jwt.DecodeError) as exc:
68+
except (
69+
jwt.InvalidTokenError,
70+
jwt.ExpiredSignatureError,
71+
jwt.DecodeError,
72+
) as exc:
6973
raise TokenError(str(exc))
7074
return jwt_data

tests/test_backend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ def func(payload):
3636
USER_MODEL.objects, "get_or_create_for_cognito", func, raising=False
3737
)
3838

39-
request = rf.get("/", HTTP_AUTHORIZATION=b"bearer %s" % token)
39+
request = rf.get("/", HTTP_AUTHORIZATION=b"bearer %s" % token.encode("utf8"))
4040
auth = backend.JSONWebTokenAuthentication()
4141
user, auth_token = auth.authenticate(request)
4242
assert user
4343
assert user.username == "username"
44-
assert auth_token == token
44+
assert auth_token == token.encode("utf8")
4545

4646

4747
def test_authenticate_invalid(rf, cognito_well_known_keys, jwk_private_key_two):
@@ -54,7 +54,7 @@ def test_authenticate_invalid(rf, cognito_well_known_keys, jwk_private_key_two):
5454
},
5555
)
5656

57-
request = rf.get("/", HTTP_AUTHORIZATION=b"bearer %s" % token)
57+
request = rf.get("/", HTTP_AUTHORIZATION=b"bearer %s" % token.encode("utf8"))
5858
auth = backend.JSONWebTokenAuthentication()
5959

6060
with pytest.raises(AuthenticationFailed):

0 commit comments

Comments
 (0)