Skip to content

Commit

Permalink
feat!: Major upgrade to pyjwt 2.1.0 (#125)
Browse files Browse the repository at this point in the history
BREAKING CHANGES (auth-backend):
- ``jwt.decode``: Inside ``EdXOAuth2::user_data`` Require explicit algorithms by default.

BREAKING CHANGES (pyjwt):
- ``jwt.decode``: dropped deprecated verify param.
- ``jwt.decode``: requires explicit algorithms argument.
- ``jwt.decode``: Returns string (in place of bytes), and no longer requires decoding.
- For more details, visit this: https://pyjwt.readthedocs.io/en/stable/changelog.html#v2-1-0
  • Loading branch information
awais786 committed Aug 10, 2021
1 parent e5c019e commit 3796072
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 32 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -14,6 +14,16 @@ Unreleased

*

[4.0.0] - 2021-08-05
--------------------

Changed
~~~~~~~

* **BREAKING CHANGE:** ``jwt.decode``: Inside ``EdXOAuth2::user_data`` Require explicit algorithms by default.
* **BREAKING CHANGE:** Upgraded dependency ``pyjwt[crypto]`` to 2.1.0, which introduces its own breaking changes that may affect consumers of this library. Pay careful attention to the 2.0.0 breaking changes documented in https://pyjwt.readthedocs.io/en/stable/changelog.html#v2-0-0.


[3.4.0] - 2021-07-07
--------------------

Expand Down
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -28,6 +28,10 @@ $(COMMON_CONSTRAINTS_TXT):

upgrade: export CUSTOM_COMPILE_COMMAND=make upgrade
upgrade: $(COMMON_CONSTRAINTS_TXT) ## update the requirements/*.txt files with the latest packages satisfying requirements/*.in
sed 's/pyjwt\[crypto\]==1.7.1//g' requirements/common_constraints.txt > requirements/common_constraints.tmp
mv requirements/common_constraints.tmp requirements/common_constraints.txt
sed 's/social-auth-core<4.0.3//g' requirements/common_constraints.txt > requirements/common_constraints.tmp
mv requirements/common_constraints.tmp requirements/common_constraints.txt
pip install -qr requirements/pip-tools.txt
# Make sure to compile files after any other files they include!
$(PIP_COMPILE) --allow-unsafe --rebuild -o requirements/pip.txt requirements/pip.in
Expand Down
2 changes: 1 addition & 1 deletion auth_backends/__init__.py
Expand Up @@ -3,4 +3,4 @@
These package is designed to be used primarily with Open edX Django projects, but should be compatible with non-edX
projects as well.
"""
__version__ = '3.4.0' # pragma: no cover
__version__ = '4.0.0' # pragma: no cover
5 changes: 3 additions & 2 deletions auth_backends/backends.py
Expand Up @@ -100,8 +100,9 @@ def auth_complete(self, *args, **kwargs):
return user

def user_data(self, access_token, *args, **kwargs):
decoded_access_token = jwt.decode(access_token, verify=False)

# The algorithm is required but unused because signature verification is skipped.
# Note: signature verification happens earlier during the authentication process.
decoded_access_token = jwt.decode(access_token, algorithms=["HS256"], options={"verify_signature": False})
keys = list(self.CLAIMS_TO_DETAILS_KEY_MAP.keys()) + ['administrator', 'superuser']
user_data = {key: decoded_access_token[key] for key in keys if key in decoded_access_token}
return user_data
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.in
Expand Up @@ -2,7 +2,7 @@
-c constraints.txt

Django
PyJWT
pyjwt[crypto]>=2.1.0 # depends on newer jwt.decode and jwt.encode functionality
six
social-auth-app-django
social-auth-core # Common auth interfaces
9 changes: 2 additions & 7 deletions requirements/base.txt
Expand Up @@ -30,10 +30,8 @@ oauthlib==3.1.1
# social-auth-core
pycparser==2.20
# via cffi
pyjwt[crypto]==1.7.1
pyjwt[crypto]==2.1.0
# via
# -c requirements/common_constraints.txt
# -c requirements/constraints.txt
# -r requirements/base.in
# social-auth-core
python3-openid==3.2.0
Expand All @@ -50,15 +48,12 @@ six==1.16.0
# via
# -r requirements/base.in
# social-auth-app-django
# social-auth-core
social-auth-app-django==4.0.0
# via
# -c requirements/common_constraints.txt
# -r requirements/base.in
social-auth-core==4.0.2
social-auth-core==4.1.0
# via
# -c requirements/common_constraints.txt
# -c requirements/constraints.txt
# -r requirements/base.in
# social-auth-app-django
sqlparse==0.4.1
Expand Down
4 changes: 2 additions & 2 deletions requirements/common_constraints.txt
Expand Up @@ -19,10 +19,10 @@ Django<2.3
drf-jwt<1.19.1

# Newer versions causing tests failures in multiple repos.
pyjwt[crypto]==1.7.1


# latest version requires PyJWT>=2.0.0 but drf-jwt requires PyJWT[crypto]<2.0.0,>=1.5.2
social-auth-core<4.0.3


# 5.0.0+ of social-auth-app-django requires social-auth-core>=4.1.0
social-auth-app-django<5.0.0
5 changes: 0 additions & 5 deletions requirements/constraints.txt
Expand Up @@ -9,8 +9,3 @@
# linking to it here is good.

-c common_constraints.txt

# greater versions causing failures in IDAs.
pyjwt==1.7.1
# social-auth-core>=4.0.3 requires PyJWT>=2.0.0
social-auth-core<4.0.3
9 changes: 2 additions & 7 deletions requirements/dev.txt
Expand Up @@ -177,10 +177,8 @@ pycryptodomex==3.10.1
# pyjwkest
pyjwkest==1.4.2
# via -r requirements/test.txt
pyjwt[crypto]==1.7.1
pyjwt[crypto]==2.1.0
# via
# -c requirements/common_constraints.txt
# -c requirements/constraints.txt
# -r requirements/test.txt
# social-auth-core
pylint==2.9.6
Expand Down Expand Up @@ -252,18 +250,15 @@ six==1.16.0
# edx-lint
# pyjwkest
# social-auth-app-django
# social-auth-core
# tox
# unittest2
# virtualenv
social-auth-app-django==4.0.0
# via
# -c requirements/common_constraints.txt
# -r requirements/test.txt
social-auth-core==4.0.2
social-auth-core==4.1.0
# via
# -c requirements/common_constraints.txt
# -c requirements/constraints.txt
# -r requirements/test.txt
# social-auth-app-django
sqlparse==0.4.1
Expand Down
9 changes: 2 additions & 7 deletions requirements/test.txt
Expand Up @@ -114,10 +114,8 @@ pycryptodomex==3.10.1
# via pyjwkest
pyjwkest==1.4.2
# via -r requirements/test.in
pyjwt[crypto]==1.7.1
pyjwt[crypto]==2.1.0
# via
# -c requirements/common_constraints.txt
# -c requirements/constraints.txt
# -r requirements/base.txt
# social-auth-core
pylint==2.9.6
Expand Down Expand Up @@ -172,18 +170,15 @@ six==1.16.0
# edx-lint
# pyjwkest
# social-auth-app-django
# social-auth-core
# tox
# unittest2
# virtualenv
social-auth-app-django==4.0.0
# via
# -c requirements/common_constraints.txt
# -r requirements/base.txt
social-auth-core==4.0.2
social-auth-core==4.1.0
# via
# -c requirements/common_constraints.txt
# -c requirements/constraints.txt
# -r requirements/base.txt
# social-auth-app-django
sqlparse==0.4.1
Expand Down

0 comments on commit 3796072

Please sign in to comment.