Skip to content

Commit 3901680

Browse files
committed
Switch jwt library from 'jwt' to 'PyJWT'
1 parent 33c6423 commit 3901680

File tree

8 files changed

+371
-160
lines changed

8 files changed

+371
-160
lines changed

CHANGES.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
1.0.4
2+
-----
3+
- switch jwt library to pyjwt
4+
5+
16
1.0.3
27
-----
38
- fix drf spectacular schema generation

django_pyoidc/views.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from importlib import import_module
33
from typing import Any, Dict, Optional, TypeVar, Union
44

5+
import jwt
6+
57
# import oic
68
from django.conf import settings
79
from django.contrib import auth, messages
@@ -13,8 +15,6 @@
1315
from django.utils.http import url_has_allowed_host_and_scheme
1416
from django.views import View
1517
from django.views.decorators.csrf import csrf_exempt
16-
from jwt import JWT
17-
from jwt.exceptions import JWTDecodeError
1818
from oic.utils.http_util import BadRequest
1919

2020
from django_pyoidc.client import OIDCClient
@@ -308,8 +308,9 @@ def post(self, request: HttpRequest) -> HttpResponse:
308308
result = HttpResponse("")
309309
try:
310310
body = request.body.decode("utf-8")[13:]
311-
decoded = JWT().decode(body, do_verify=False) # type: ignore[no-untyped-call] # jwt.JWT is not typed yet
312-
311+
# Here we do not perform validation because we assume that is later performed by
312+
# `logout_sessions_by_sub`/`logout_sessions_by_sid` when calling pyoidc.
313+
decoded = jwt.decode(body, options={"verify_signature": False})
313314
sid = decoded.get("sid")
314315
sub = decoded.get("sub")
315316
if sub:
@@ -329,7 +330,7 @@ def post(self, request: HttpRequest) -> HttpResponse:
329330
result.status_code = 400
330331
result.content = "Got invalid logout token : sub or sid is missing"
331332
logger.debug("Got invalid logout token : sub or sid is missing")
332-
except JWTDecodeError:
333+
except jwt.PyJWTError:
333334
result.status_code = 400
334335
except UnicodeDecodeError as e:
335336
raise SuspiciousOperation(e)

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dependencies = [
3737
"oic==1.7.0",
3838
"django>=3.2",
3939
"jsonpickle",
40-
"jwt",
40+
"pyjwt",
4141
"pycryptodomex",
4242
]
4343
license-files = ['LICENSE']

requirements/requirements-dev.txt

+145-36
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,51 @@
11
#
2-
# This file is autogenerated by pip-compile with Python 3.8
2+
# This file is autogenerated by pip-compile with Python 3.10
33
# by the following command:
44
#
5-
# pip-compile requirements/requirements-dev.in
5+
# pip-compile --output-file=requirements/requirements-dev.txt requirements/requirements-dev.in
66
#
7+
anyio==4.9.0
8+
# via httpx
79
asgiref==3.8.1
810
# via
911
# -c requirements/requirements.txt
1012
# django
1113
# django-stubs
12-
backports-zoneinfo==0.2.1
13-
# via
14-
# -c requirements/requirements.txt
15-
# django
14+
backports-tarfile==1.2.0
15+
# via jaraco-context
16+
black==25.1.0
17+
# via -r requirements/requirements-dev.in
1618
build==1.2.2.post1
1719
# via pip-tools
18-
certifi==2024.12.14
20+
certifi==2025.1.31
1921
# via
2022
# -c requirements/requirements.txt
23+
# httpcore
24+
# httpx
2125
# requests
26+
cffi==1.17.1
27+
# via
28+
# -c requirements/requirements.txt
29+
# cryptography
2230
cfgv==3.4.0
2331
# via pre-commit
2432
charset-normalizer==3.4.1
2533
# via
2634
# -c requirements/requirements.txt
2735
# requests
2836
click==8.1.8
29-
# via pip-tools
37+
# via
38+
# black
39+
# hatch
40+
# pip-tools
41+
# userpath
42+
cryptography==44.0.2
43+
# via
44+
# -c requirements/requirements.txt
45+
# secretstorage
3046
distlib==0.3.9
3147
# via virtualenv
32-
django==4.2.18
48+
django==5.1.7
3349
# via
3450
# -c requirements/requirements.txt
3551
# django-stubs
@@ -38,37 +54,109 @@ django-stubs[compatible-mypy]==5.1.0
3854
# via
3955
# -r requirements/requirements-dev.in
4056
# djangorestframework-stubs
41-
django-stubs-ext==5.1.2
57+
django-stubs-ext==5.1.3
4258
# via django-stubs
4359
djangorestframework-stubs[compatible-mypy]==3.15.1
4460
# via -r requirements/requirements-dev.in
45-
filelock==3.16.1
61+
exceptiongroup==1.2.2
62+
# via anyio
63+
filelock==3.18.0
4664
# via virtualenv
47-
identify==2.6.1
65+
flake8==7.2.0
66+
# via -r requirements/requirements-dev.in
67+
h11==0.14.0
68+
# via httpcore
69+
hatch==1.14.0
70+
# via -r requirements/requirements-dev.in
71+
hatchling==1.27.0
72+
# via hatch
73+
httpcore==1.0.7
74+
# via httpx
75+
httpx==0.28.1
76+
# via hatch
77+
hyperlink==21.0.0
78+
# via hatch
79+
identify==2.6.9
4880
# via pre-commit
4981
idna==3.10
5082
# via
5183
# -c requirements/requirements.txt
84+
# anyio
85+
# httpx
86+
# hyperlink
5287
# requests
53-
importlib-metadata==8.5.0
54-
# via build
88+
importlib-metadata==8.6.1
89+
# via keyring
90+
isort==6.0.1
91+
# via -r requirements/requirements-dev.in
92+
jaraco-classes==3.4.0
93+
# via keyring
94+
jaraco-context==6.0.1
95+
# via keyring
96+
jaraco-functools==4.1.0
97+
# via keyring
98+
jeepney==0.9.0
99+
# via
100+
# keyring
101+
# secretstorage
102+
keyring==25.6.0
103+
# via hatch
104+
markdown-it-py==3.0.0
105+
# via rich
106+
mccabe==0.7.0
107+
# via flake8
108+
mdurl==0.1.2
109+
# via markdown-it-py
110+
more-itertools==10.6.0
111+
# via
112+
# jaraco-classes
113+
# jaraco-functools
55114
mypy==1.11.2
56115
# via
57116
# -r requirements/requirements-dev.in
58117
# django-stubs
59118
# djangorestframework-stubs
60119
mypy-extensions==1.0.0
61-
# via mypy
120+
# via
121+
# black
122+
# mypy
62123
nodeenv==1.9.1
63124
# via pre-commit
64125
packaging==24.2
65-
# via build
126+
# via
127+
# black
128+
# build
129+
# hatch
130+
# hatchling
131+
pathspec==0.12.1
132+
# via
133+
# black
134+
# hatchling
135+
pexpect==4.9.0
136+
# via hatch
66137
pip-tools==7.4.1
67138
# via -r requirements/requirements-dev.in
68-
platformdirs==4.3.6
69-
# via virtualenv
70-
pre-commit==3.5.0
139+
platformdirs==4.3.7
140+
# via
141+
# black
142+
# hatch
143+
# virtualenv
144+
pluggy==1.5.0
145+
# via hatchling
146+
pre-commit==4.2.0
71147
# via -r requirements/requirements-dev.in
148+
ptyprocess==0.7.0
149+
# via pexpect
150+
pycodestyle==2.13.0
151+
# via flake8
152+
pycparser==2.22
153+
# via
154+
# -c requirements/requirements.txt
155+
# cffi
156+
pyflakes==3.3.2
157+
# via flake8
158+
pygments==2.19.1
159+
# via rich
72160
pyproject-hooks==1.2.0
73161
# via
74162
# build
@@ -81,55 +169,76 @@ requests==2.32.3
81169
# via
82170
# -c requirements/requirements.txt
83171
# djangorestframework-stubs
84-
ruff==0.9.1
85-
# via -r requirements/requirements-dev.in
172+
rich==14.0.0
173+
# via hatch
174+
secretstorage==3.3.3
175+
# via keyring
176+
shellingham==1.5.4
177+
# via hatch
178+
sniffio==1.3.1
179+
# via anyio
86180
sqlparse==0.5.3
87181
# via
88182
# -c requirements/requirements.txt
89183
# django
90184
tomli==2.2.1
91185
# via
186+
# black
92187
# build
93188
# django-stubs
189+
# hatchling
94190
# mypy
95191
# pip-tools
192+
tomli-w==1.2.0
193+
# via hatch
194+
tomlkit==0.13.2
195+
# via hatch
196+
trove-classifiers==2025.3.19.19
197+
# via hatchling
96198
types-docutils==0.21.0.20241128
97199
# via types-pygments
98-
types-markdown==3.7.0.20241204
200+
types-markdown==3.7.0.20250322
99201
# via -r requirements/requirements-dev.in
100-
types-psycopg2==2.9.21.20241019
202+
types-psycopg2==2.9.21.20250318
101203
# via -r requirements/requirements-dev.in
102-
types-pygments==2.19.0.20250107
204+
types-pygments==2.19.0.20250305
103205
# via -r requirements/requirements-dev.in
104-
types-pyyaml==6.0.12.20241230
206+
types-pyyaml==6.0.12.20250326
105207
# via
106208
# django-stubs
107209
# djangorestframework-stubs
108-
types-requests==2.32.0.20241016
210+
types-requests==2.32.0.20250328
109211
# via djangorestframework-stubs
110-
types-setuptools==75.8.0.20250110
111-
# via types-pygments
112-
typing-extensions==4.12.2
212+
typing-extensions==4.13.0
113213
# via
114214
# -c requirements/requirements.txt
215+
# anyio
115216
# asgiref
217+
# black
116218
# django-stubs
117219
# django-stubs-ext
118220
# djangorestframework-stubs
119221
# mypy
120-
urllib3==2.2.3
222+
# rich
223+
urllib3==2.3.0
121224
# via
122225
# -c requirements/requirements.txt
123226
# requests
124227
# types-requests
125-
virtualenv==20.29.0
126-
# via pre-commit
228+
userpath==1.9.2
229+
# via hatch
230+
uv==0.6.11
231+
# via hatch
232+
virtualenv==20.30.0
233+
# via
234+
# hatch
235+
# pre-commit
127236
wheel==0.45.1
128237
# via pip-tools
129-
zipp==3.20.2
130-
# via
131-
# -c requirements/requirements.txt
132-
# importlib-metadata
238+
zipp==3.21.0
239+
# via importlib-metadata
240+
zstandard==0.23.0
241+
# via hatch
133242

134243
# The following packages are considered to be unsafe in a requirements file:
135244
# pip

0 commit comments

Comments
 (0)