Skip to content

Commit b7020a8

Browse files
committed
Upgrade PyJWT to 2.10.0+
- Update PyJWT dependency from <2.10.0 to >=2.10.0 - Update requires-python from >=3.8 to >=3.9 (PyJWT 2.10.0 dropped Python 3.8) - Remove Python 3.8 from test matrix - Fix JWT token handling to use custom claim instead of 'sub' PyJWT 2.10.0 added validation that the 'sub' (subject) claim must be a string per RFC 7519. The code was storing a dict in the 'sub' claim, which now fails with InvalidSubjectError. Changed to use a custom 'access_token_data' claim instead.
1 parent 8001908 commit b7020a8

File tree

4 files changed

+521
-3881
lines changed

4 files changed

+521
-3881
lines changed

jhub_apps/service/auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
def _create_access_token(data: dict, expires_delta: typing.Optional[timedelta] = None):
1313
logger.info("Creating access token")
14-
to_encode = data.copy()
14+
to_encode = {"access_token_data": data.get("sub", data)}
1515
if expires_delta:
1616
expire = datetime.utcnow() + expires_delta
1717
else:
@@ -33,7 +33,7 @@ def _get_jhub_token_from_jwt_token(token):
3333
)
3434
try:
3535
payload = jwt.decode(token, os.environ["JHUB_APP_JWT_SECRET_KEY"], algorithms=["HS256"])
36-
access_token_data: dict = payload.get("sub")
36+
access_token_data: dict = payload.get("access_token_data")
3737
if access_token_data is None:
3838
raise credentials_exception
3939
except jwt.PyJWTError as e:

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66
name = "jhub-apps"
77
description = 'JupyterHub Apps'
88
readme = "README.md"
9-
requires-python = ">=3.8"
9+
requires-python = ">=3.9"
1010
license = "MIT"
1111

1212
dependencies = [
@@ -26,7 +26,7 @@ dependencies = [
2626
"python-slugify",
2727
"cachetools",
2828
"structlog",
29-
"PyJWT<2.10.0",
29+
"PyJWT>=2.10.0",
3030
"GitPython",
3131
# pinning to avoid unexpected changes in spec causing
3232
# unexpected breakage
@@ -63,7 +63,7 @@ dependencies = [
6363
]
6464

6565
[[tool.hatch.envs.test.matrix]]
66-
python = ["38", "39", "310", "311", "312"]
66+
python = ["39", "310", "311", "312"]
6767

6868
[tool.coverage.run]
6969
branch = true

ui/package-lock.json

Lines changed: 15 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)