Skip to content

Commit 24a5b2f

Browse files
committed
Handle deprecations
1 parent e490f9d commit 24a5b2f

File tree

5 files changed

+239
-164
lines changed

5 files changed

+239
-164
lines changed

jwt/api_jws.py

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import binascii
22
import json
3-
import warnings
43

54
from .algorithms import requires_cryptography # NOQA
65
from .algorithms import Algorithm, get_default_algorithms, has_crypto
@@ -132,7 +131,6 @@ def decode(
132131
self,
133132
jwt, # type: str
134133
key="", # type: str
135-
verify=True, # type: bool
136134
algorithms=None, # type: List[str]
137135
options=None, # type: Dict
138136
complete=False, # type: bool
@@ -143,23 +141,14 @@ def decode(
143141
verify_signature = merged_options["verify_signature"]
144142

145143
if verify_signature and not algorithms:
146-
warnings.warn(
147-
"It is strongly recommended that you pass in a "
144+
raise DecodeError(
145+
"It is required that you pass in a "
148146
+ 'value for the "algorithms" argument when calling decode(). '
149-
+ "This argument will be mandatory in a future version.",
150-
DeprecationWarning,
151147
)
152148

153149
payload, signing_input, header, signature = self._load(jwt)
154150

155-
if not verify:
156-
warnings.warn(
157-
"The verify parameter is deprecated. "
158-
"Please use verify_signature in options instead.",
159-
DeprecationWarning,
160-
stacklevel=2,
161-
)
162-
elif verify_signature:
151+
if verify_signature:
163152
self._verify_signature(
164153
payload, signing_input, header, signature, key, algorithms
165154
)
@@ -225,13 +214,7 @@ def _load(self, jwt):
225214
return (payload, signing_input, header, signature)
226215

227216
def _verify_signature(
228-
self,
229-
payload,
230-
signing_input,
231-
header,
232-
signature,
233-
key="",
234-
algorithms=None,
217+
self, payload, signing_input, header, signature, key, algorithms
235218
):
236219

237220
alg = header.get("alg")

jwt/api_jwt.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
import warnings
32
from calendar import timegm
43
from datetime import datetime, timedelta
54

@@ -77,28 +76,25 @@ def decode(
7776
self,
7877
jwt, # type: str
7978
key="", # type: str
80-
verify=True, # type: bool
8179
algorithms=None, # type: List[str]
8280
options=None, # type: Dict
8381
complete=False, # type: bool
8482
**kwargs
8583
):
8684
# type: (...) -> Dict[str, Any]
8785

88-
if verify and not algorithms:
89-
warnings.warn(
90-
"It is strongly recommended that you pass in a "
91-
+ 'value for the "algorithms" argument when calling decode(). '
92-
+ "This argument will be mandatory in a future version.",
93-
DeprecationWarning,
94-
)
95-
9686
payload, _, _, _ = self._load(jwt)
9787

9888
if options is None:
99-
options = {"verify_signature": verify}
89+
options = {"verify_signature": True}
10090
else:
101-
options.setdefault("verify_signature", verify)
91+
options.setdefault("verify_signature", True)
92+
93+
if options["verify_signature"] and not algorithms:
94+
raise DecodeError(
95+
"It is required that you pass in a "
96+
+ 'value for the "algorithms" argument when calling decode(). '
97+
)
10298

10399
decoded = super(PyJWT, self).decode(
104100
jwt,
@@ -119,7 +115,7 @@ def decode(
119115
if not isinstance(payload, dict):
120116
raise DecodeError("Invalid payload string: must be a json object")
121117

122-
if verify:
118+
if options["verify_signature"]:
123119
merged_options = merge_dict(self.options, options)
124120
self._validate_claims(payload, merged_options, **kwargs)
125121

@@ -133,14 +129,6 @@ def _validate_claims(
133129
self, payload, options, audience=None, issuer=None, leeway=0, **kwargs
134130
):
135131

136-
if "verify_expiration" in kwargs:
137-
options["verify_exp"] = kwargs.get("verify_expiration", True)
138-
warnings.warn(
139-
"The verify_expiration parameter is deprecated. "
140-
"Please use verify_exp in options instead.",
141-
DeprecationWarning,
142-
)
143-
144132
if isinstance(leeway, timedelta):
145133
leeway = leeway.total_seconds()
146134

0 commit comments

Comments
 (0)