Skip to content
This repository was archived by the owner on Sep 29, 2023. It is now read-only.

Commit 9ce5164

Browse files
authored
Merge pull request #246 from AzureAD/compatible-with-both-pyjwt-1-and-2
Make it compatible with PyJWT 1 & 2
2 parents 01f6fad + 914e83e commit 9ce5164

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

adal/self_signed_jwt.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ def _sign_jwt(header, payload, certificate):
5757
return encoded_jwt
5858

5959
def _encode_jwt(payload, certificate, header):
60-
return jwt.encode(payload, certificate, algorithm='RS256', headers=header).decode()
60+
encoded = jwt.encode(payload, certificate, algorithm='RS256', headers=header)
61+
try:
62+
return encoded.decode() # PyJWT 1.x returns bytes; historically we convert it to string
63+
except AttributeError:
64+
return encoded # PyJWT 2 will return string
6165

6266
def _raise_on_invalid_jwt_signature(encoded_jwt):
6367
segments = encoded_jwt.split('.')

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@
7676
],
7777
packages=['adal'],
7878
install_requires=[
79-
'PyJWT>=1.0.0',
80-
'requests>=2.0.0',
81-
'python-dateutil>=2.1.0',
79+
'PyJWT>=1.0.0,<3',
80+
'requests>=2.0.0,<3',
81+
'python-dateutil>=2.1.0,<3',
8282
'cryptography>=1.1.0'
8383
]
8484
)

0 commit comments

Comments
 (0)