Skip to content

Commit d5459b8

Browse files
committed
Fix requires_cryptography exception on older pyjwt versions (hopefully)
This should fix import errors when trying to use requires_cryptography on older versions of pyjwt. Refs #42
1 parent 0f9fa91 commit d5459b8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

flask_jwt_extended/config.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,18 @@
33

44
import simplekv
55
from flask import current_app
6-
from jwt.algorithms import requires_cryptography
6+
7+
# Older versions of pyjwt do not have the requires_cryptography set. Also,
8+
# older versions will not be adding new algorithms to them, so I can hard code
9+
# the default version here and be safe. If there is a newer algorithm someone
10+
# wants to use, they will need newer versions of pyjwt and it will be included
11+
# in their requires_cryptography set, and if they attempt to use it in older
12+
# versions of pyjwt, it will kick it out as an unrecognized algorithm.
13+
try:
14+
from jwt.algorithms import requires_cryptography
15+
except ImportError:
16+
requires_cryptography = {'RS256', 'RS384', 'RS512', 'ES256', 'ES384',
17+
'ES521', 'ES512', 'PS256', 'PS384', 'PS512'}
718

819

920
class _Config(object):

0 commit comments

Comments
 (0)