Skip to content

Commit f690976

Browse files
authored
Drop deprecation warnings (#515)
* Drop deprecation warnings * Add missing keys * Remove commented exceptions * Undo lambda change * Remove unused keys
1 parent c385335 commit f690976

18 files changed

+341
-336
lines changed

jwt/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@
99
)
1010
from .exceptions import (
1111
DecodeError,
12-
ExpiredSignature,
1312
ExpiredSignatureError,
1413
ImmatureSignatureError,
1514
InvalidAlgorithmError,
16-
InvalidAudience,
1715
InvalidAudienceError,
1816
InvalidIssuedAtError,
19-
InvalidIssuer,
2017
InvalidIssuerError,
2118
InvalidSignatureError,
2219
InvalidTokenError,
@@ -54,14 +51,11 @@
5451
"unregister_algorithm",
5552
# Exceptions
5653
"DecodeError",
57-
"ExpiredSignature",
5854
"ExpiredSignatureError",
5955
"ImmatureSignatureError",
6056
"InvalidAlgorithmError",
61-
"InvalidAudience",
6257
"InvalidAudienceError",
6358
"InvalidIssuedAtError",
64-
"InvalidIssuer",
6559
"InvalidIssuerError",
6660
"InvalidSignatureError",
6761
"InvalidTokenError",

jwt/api_jws.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import binascii
22
import json
3-
import warnings
43
from collections.abc import Mapping
54

65
from .algorithms import requires_cryptography # NOQA
@@ -145,24 +144,13 @@ def decode(
145144
verify_signature = merged_options["verify_signature"]
146145

147146
if verify_signature and not algorithms:
148-
warnings.warn(
149-
"It is strongly recommended that you pass in a "
150-
+ 'value for the "algorithms" argument when calling decode(). '
151-
+ "This argument will be mandatory in a future version.",
152-
DeprecationWarning,
153-
stacklevel=2,
147+
raise DecodeError(
148+
'It is required that you pass in a value for the "algorithms" argument when calling decode().'
154149
)
155150

156151
payload, signing_input, header, signature = self._load(jwt)
157152

158-
if not verify:
159-
warnings.warn(
160-
"The verify parameter is deprecated. "
161-
"Please use verify_signature in options instead.",
162-
DeprecationWarning,
163-
stacklevel=2,
164-
)
165-
elif verify_signature:
153+
if verify_signature:
166154
self._verify_signature(
167155
payload, signing_input, header, signature, key, algorithms
168156
)

jwt/api_jwt.py

Lines changed: 11 additions & 46 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 collections.abc import Iterable, Mapping
54
from datetime import datetime, timedelta
@@ -26,7 +25,6 @@
2625

2726
class PyJWT(PyJWS):
2827
header_type = "JWT"
29-
deprecated_requires = ["require_exp", "require_iat", "require_nbf"]
3028

3129
@staticmethod
3230
def _get_default_options():
@@ -76,29 +74,23 @@ def decode(
7674
self,
7775
jwt, # type: str
7876
key="", # type: str
79-
verify=True, # type: bool
8077
algorithms=None, # type: List[str]
8178
options=None, # type: Dict
8279
complete=False, # type: bool
8380
**kwargs
84-
):
85-
# type: (...) -> Dict[str, Any]
86-
87-
if verify and not algorithms:
88-
warnings.warn(
89-
"It is strongly recommended that you pass in a "
90-
+ 'value for the "algorithms" argument when calling decode(). '
91-
+ "This argument will be mandatory in a future version.",
92-
DeprecationWarning,
93-
stacklevel=2,
94-
)
81+
): # type: (...) -> Dict[str, Any]
9582

9683
payload, _, _, _ = self._load(jwt)
9784

9885
if options is None:
99-
options = {"verify_signature": verify}
86+
options = {"verify_signature": True}
10087
else:
101-
options.setdefault("verify_signature", verify)
88+
options.setdefault("verify_signature", True)
89+
90+
if options["verify_signature"] and not algorithms:
91+
raise DecodeError(
92+
'It is required that you pass in a value for the "algorithms" argument when calling decode().'
93+
)
10294

10395
decoded = super().decode(
10496
jwt,
@@ -119,7 +111,7 @@ def decode(
119111
if not isinstance(payload, dict):
120112
raise DecodeError("Invalid payload string: must be a json object")
121113

122-
if verify:
114+
if options["verify_signature"]:
123115
merged_options = merge_dict(self.options, options)
124116
self._validate_claims(payload, merged_options, **kwargs)
125117

@@ -132,38 +124,11 @@ def decode(
132124
def _validate_claims(
133125
self, payload, options, audience=None, issuer=None, leeway=0, **kwargs
134126
):
135-
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-
stacklevel=3,
143-
)
144-
145-
verify_claims = {
146-
required
147-
for required in self.deprecated_requires
148-
if required in options
149-
}
150-
require_options = options.setdefault("require", [])
151-
for opt in verify_claims:
152-
opt_claim = opt.split("require_", 1)[1]
153-
if options[opt]:
154-
require_options.append(opt_claim)
155-
warnings.warn(
156-
"The {} parameter is deprecated. Please add {} to"
157-
" the require list in options instead".format(opt, opt_claim),
158-
DeprecationWarning,
159-
stacklevel=3,
160-
)
161-
162127
if isinstance(leeway, timedelta):
163128
leeway = leeway.total_seconds()
164129

165-
if not isinstance(audience, (type(None), Iterable)):
166-
raise TypeError("audience must be an iterable or None")
130+
if not isinstance(audience, (bytes, str, type(None), Iterable)):
131+
raise TypeError("audience must be a string, iterable, or None")
167132

168133
self._validate_required_claims(payload, options)
169134

jwt/exceptions.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,3 @@ class PyJWKSetError(PyJWTError):
6464

6565
class PyJWKClientError(PyJWTError):
6666
pass
67-
68-
69-
# Compatibility aliases (deprecated)
70-
ExpiredSignature = ExpiredSignatureError
71-
InvalidAudience = InvalidAudienceError
72-
InvalidIssuer = InvalidIssuerError

jwt/jwks_client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def get_signing_key(self, kid):
5959
return signing_key
6060

6161
def get_signing_key_from_jwt(self, token):
62-
unverified = decode_token(token, complete=True, verify=False)
62+
unverified = decode_token(
63+
token, complete=True, options={"verify_signature": False}
64+
)
6365
header = unverified.get("header")
6466
return self.get_signing_key(header.get("kid"))

tests/keys/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def decode_value(val):
1313

1414

1515
def load_hmac_key():
16-
with open(os.path.join(BASE_PATH, "jwk_hmac.json")) as infile:
16+
with open(os.path.join(BASE_PATH, "jwk_hmac.json"), "r") as infile:
1717
keyobj = json.load(infile)
1818

1919
return base64url_decode(force_bytes(keyobj["k"]))
@@ -31,24 +31,26 @@ def load_hmac_key():
3131
if has_crypto:
3232

3333
def load_rsa_key():
34-
with open(os.path.join(BASE_PATH, "jwk_rsa_key.json")) as infile:
34+
with open(os.path.join(BASE_PATH, "jwk_rsa_key.json"), "r") as infile:
3535
return RSAAlgorithm.from_jwk(infile.read())
3636

3737
def load_rsa_pub_key():
38-
with open(os.path.join(BASE_PATH, "jwk_rsa_pub.json")) as infile:
38+
with open(os.path.join(BASE_PATH, "jwk_rsa_pub.json"), "r") as infile:
3939
return RSAAlgorithm.from_jwk(infile.read())
4040

4141
def load_ec_key():
42-
with open(os.path.join(BASE_PATH, "jwk_ec_key.json")) as infile:
42+
with open(os.path.join(BASE_PATH, "jwk_ec_key.json"), "r") as infile:
4343
keyobj = json.load(infile)
4444

4545
return ec.EllipticCurvePrivateNumbers(
4646
private_value=decode_value(keyobj["d"]),
47-
public_numbers=load_ec_pub_key().public_numbers(),
47+
public_numbers=load_ec_pub_key_p_521().public_numbers(),
4848
)
4949

50-
def load_ec_pub_key():
51-
with open(os.path.join(BASE_PATH, "jwk_ec_pub.json")) as infile:
50+
def load_ec_pub_key_p_521():
51+
with open(
52+
os.path.join(BASE_PATH, "jwk_ec_pub_P-521.json"), "r"
53+
) as infile:
5254
keyobj = json.load(infile)
5355

5456
return ec.EllipticCurvePublicNumbers(

tests/keys/jwk_ec_key.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/keys/jwk_ec_pub.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/keys/jwk_ec_pub_P-521.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"kty": "EC",
3+
4+
"crv": "P-521",
5+
"x": "AHKZLLOsCOzz5cY97ewNUajB957y-C-U88c3v13nmGZx6sYl_oJXu9A5RkTKqjqvjyekWF-7ytDyRXYgCF5cj0Kt",
6+
"y": "AdymlHvOiLxXkEhayXQnNCvDX4h9htZaCJN34kfmC6pV5OhQHiraVySsUdaQkAgDPrwQrJmbnX9cwlGfP-HqHZR1"
7+
}

tests/keys/testkey_ec

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)