Skip to content

Commit 55bf9e7

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

File tree

8 files changed

+317
-72
lines changed

8 files changed

+317
-72
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

+138-14
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,54 @@
22
# This file is autogenerated by pip-compile with Python 3.8
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.5.2
8+
# via httpx
79
asgiref==3.8.1
810
# via
911
# -c requirements/requirements.txt
1012
# django
1113
# django-stubs
14+
backports-tarfile==1.2.0
15+
# via jaraco-context
1216
backports-zoneinfo==0.2.1
1317
# via
1418
# -c requirements/requirements.txt
1519
# django
20+
black==24.8.0
21+
# via -r requirements/requirements-dev.in
1622
build==1.2.2.post1
1723
# via pip-tools
18-
certifi==2024.12.14
24+
certifi==2025.1.31
1925
# via
2026
# -c requirements/requirements.txt
27+
# httpcore
28+
# httpx
2129
# requests
30+
cffi==1.17.1
31+
# via
32+
# -c requirements/requirements.txt
33+
# cryptography
2234
cfgv==3.4.0
2335
# via pre-commit
2436
charset-normalizer==3.4.1
2537
# via
2638
# -c requirements/requirements.txt
2739
# requests
2840
click==8.1.8
29-
# via pip-tools
41+
# via
42+
# black
43+
# hatch
44+
# pip-tools
45+
# userpath
46+
cryptography==44.0.2
47+
# via
48+
# -c requirements/requirements.txt
49+
# secretstorage
3050
distlib==0.3.9
3151
# via virtualenv
32-
django==4.2.18
52+
django==4.2.20
3353
# via
3454
# -c requirements/requirements.txt
3555
# django-stubs
@@ -38,37 +58,115 @@ django-stubs[compatible-mypy]==5.1.0
3858
# via
3959
# -r requirements/requirements-dev.in
4060
# djangorestframework-stubs
41-
django-stubs-ext==5.1.2
61+
django-stubs-ext==5.1.3
4262
# via django-stubs
4363
djangorestframework-stubs[compatible-mypy]==3.15.1
4464
# via -r requirements/requirements-dev.in
65+
exceptiongroup==1.2.2
66+
# via anyio
4567
filelock==3.16.1
4668
# via virtualenv
69+
flake8==7.1.2
70+
# via -r requirements/requirements-dev.in
71+
h11==0.14.0
72+
# via httpcore
73+
hatch==1.14.0
74+
# via -r requirements/requirements-dev.in
75+
hatchling==1.27.0
76+
# via hatch
77+
httpcore==1.0.7
78+
# via httpx
79+
httpx==0.28.1
80+
# via hatch
81+
hyperlink==21.0.0
82+
# via hatch
4783
identify==2.6.1
4884
# via pre-commit
4985
idna==3.10
5086
# via
5187
# -c requirements/requirements.txt
88+
# anyio
89+
# httpx
90+
# hyperlink
5291
# requests
5392
importlib-metadata==8.5.0
54-
# via build
93+
# via
94+
# build
95+
# keyring
96+
importlib-resources==6.4.5
97+
# via
98+
# -c requirements/requirements.txt
99+
# keyring
100+
isort==5.13.2
101+
# via -r requirements/requirements-dev.in
102+
jaraco-classes==3.4.0
103+
# via keyring
104+
jaraco-context==6.0.1
105+
# via keyring
106+
jaraco-functools==4.1.0
107+
# via keyring
108+
jeepney==0.9.0
109+
# via
110+
# keyring
111+
# secretstorage
112+
keyring==25.5.0
113+
# via hatch
114+
markdown-it-py==3.0.0
115+
# via rich
116+
mccabe==0.7.0
117+
# via flake8
118+
mdurl==0.1.2
119+
# via markdown-it-py
120+
more-itertools==10.5.0
121+
# via
122+
# jaraco-classes
123+
# jaraco-functools
55124
mypy==1.11.2
56125
# via
57126
# -r requirements/requirements-dev.in
58127
# django-stubs
59128
# djangorestframework-stubs
60129
mypy-extensions==1.0.0
61-
# via mypy
130+
# via
131+
# black
132+
# mypy
62133
nodeenv==1.9.1
63134
# via pre-commit
64135
packaging==24.2
65-
# via build
136+
# via
137+
# black
138+
# build
139+
# hatch
140+
# hatchling
141+
pathspec==0.12.1
142+
# via
143+
# black
144+
# hatchling
145+
pexpect==4.9.0
146+
# via hatch
66147
pip-tools==7.4.1
67148
# via -r requirements/requirements-dev.in
68149
platformdirs==4.3.6
69-
# via virtualenv
150+
# via
151+
# black
152+
# hatch
153+
# virtualenv
154+
pluggy==1.5.0
155+
# via hatchling
70156
pre-commit==3.5.0
71157
# via -r requirements/requirements-dev.in
158+
ptyprocess==0.7.0
159+
# via pexpect
160+
pycodestyle==2.12.1
161+
# via flake8
162+
pycparser==2.22
163+
# via
164+
# -c requirements/requirements.txt
165+
# cffi
166+
pyflakes==3.2.0
167+
# via flake8
168+
pygments==2.19.1
169+
# via rich
72170
pyproject-hooks==1.2.0
73171
# via
74172
# build
@@ -81,18 +179,32 @@ requests==2.32.3
81179
# via
82180
# -c requirements/requirements.txt
83181
# djangorestframework-stubs
84-
ruff==0.9.1
85-
# via -r requirements/requirements-dev.in
182+
rich==14.0.0
183+
# via hatch
184+
secretstorage==3.3.3
185+
# via keyring
186+
shellingham==1.5.4
187+
# via hatch
188+
sniffio==1.3.1
189+
# via anyio
86190
sqlparse==0.5.3
87191
# via
88192
# -c requirements/requirements.txt
89193
# django
90194
tomli==2.2.1
91195
# via
196+
# black
92197
# build
93198
# django-stubs
199+
# hatchling
94200
# mypy
95201
# pip-tools
202+
tomli-w==1.0.0
203+
# via hatch
204+
tomlkit==0.13.2
205+
# via hatch
206+
trove-classifiers==2025.3.19.19
207+
# via hatchling
96208
types-docutils==0.21.0.20241128
97209
# via types-pygments
98210
types-markdown==3.7.0.20241204
@@ -109,27 +221,39 @@ types-requests==2.32.0.20241016
109221
# via djangorestframework-stubs
110222
types-setuptools==75.8.0.20250110
111223
# via types-pygments
112-
typing-extensions==4.12.2
224+
typing-extensions==4.13.0
113225
# via
114226
# -c requirements/requirements.txt
227+
# anyio
115228
# asgiref
229+
# black
116230
# django-stubs
117231
# django-stubs-ext
118232
# djangorestframework-stubs
119233
# mypy
234+
# rich
120235
urllib3==2.2.3
121236
# via
122237
# -c requirements/requirements.txt
123238
# requests
124239
# types-requests
125-
virtualenv==20.29.0
126-
# via pre-commit
240+
userpath==1.9.2
241+
# via hatch
242+
uv==0.6.11
243+
# via hatch
244+
virtualenv==20.30.0
245+
# via
246+
# hatch
247+
# pre-commit
127248
wheel==0.45.1
128249
# via pip-tools
129250
zipp==3.20.2
130251
# via
131252
# -c requirements/requirements.txt
132253
# importlib-metadata
254+
# importlib-resources
255+
zstandard==0.23.0
256+
# via hatch
133257

134258
# The following packages are considered to be unsafe in a requirements file:
135259
# pip

0 commit comments

Comments
 (0)