diff options
| author | Magnus Hagander | 2025-01-07 09:26:43 +0000 |
|---|---|---|
| committer | Magnus Hagander | 2025-01-07 09:26:43 +0000 |
| commit | 57ff243916b3a700b2f642393e1dc803fcb706c2 (patch) | |
| tree | b23b83e6602cfbd91d18280fc68498ba96ee5fb3 | |
| parent | 9aca53b956c646023cedd14556f2c7b2307c3046 (diff) | |
Support both old and new versions of pyjwt
Pyjwt 2.0 made some incompatible changes in how a signature is verified,
so we need to support both the old and the new one.
For cleanliness, create a util/versionutil.py that wraps these version
specific things. There are clearly more.
| -rw-r--r-- | postgresqleu/util/messaging/bluesky.py | 6 | ||||
| -rw-r--r-- | postgresqleu/util/versionutil.py | 9 |
2 files changed, 12 insertions, 3 deletions
diff --git a/postgresqleu/util/messaging/bluesky.py b/postgresqleu/util/messaging/bluesky.py index 4345db59..76e4a7dd 100644 --- a/postgresqleu/util/messaging/bluesky.py +++ b/postgresqleu/util/messaging/bluesky.py @@ -2,11 +2,11 @@ from django.core.validators import ValidationError from django import forms from datetime import datetime, timezone, timedelta -import jwt import re import requests from postgresqleu.util.image import get_image_contenttype_from_bytes +from postgresqleu.util.versionutil import decode_unverified_jwt from postgresqleu.confreg.models import MessagingProvider from postgresqleu.confreg.backendforms import BackendSeriesMessagingForm @@ -107,8 +107,8 @@ class Bluesky(object): provider.config.update({ 'accessjwt': response['accessJwt'], 'refreshjwt': response['refreshJwt'], - 'accesstokenexpires': jwt.decode(response['accessJwt'], verify=False)['exp'], - 'refreshtokenexpires': jwt.decode(response['refreshJwt'], verify=False)['exp'], + 'accesstokenexpires': decode_unverified_jwt(response['accessJwt'])['exp'], + 'refreshtokenexpires': decode_unverified_jwt(response['refreshJwt'])['exp'], 'handle': response['handle'], 'did': response['did'], }) diff --git a/postgresqleu/util/versionutil.py b/postgresqleu/util/versionutil.py new file mode 100644 index 00000000..24f17e21 --- /dev/null +++ b/postgresqleu/util/versionutil.py @@ -0,0 +1,9 @@ +# Generic wrappers to handle backwards incompatible changes in dependencies +import jwt + + +def decode_unverified_jwt(j): + if jwt.__version__ > 2: + return jwt.decode(j, options={'verify_signature': False}) + else: + return jwt.decode(j, verify=False) |
