Skip to content

Commit f9db1d7

Browse files
authored
Revert "Remove arbitrary kwargs. (#657)" (#701)
This reverts commit 5fe7f2b.
1 parent 828a20a commit f9db1d7

File tree

3 files changed

+12
-24
lines changed

3 files changed

+12
-24
lines changed

jwt/api_jws.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def decode_complete(
134134
key: str = "",
135135
algorithms: List[str] = None,
136136
options: Dict = None,
137+
**kwargs,
137138
) -> Dict[str, Any]:
138139
if options is None:
139140
options = {}
@@ -162,8 +163,9 @@ def decode(
162163
key: str = "",
163164
algorithms: List[str] = None,
164165
options: Dict = None,
166+
**kwargs,
165167
) -> str:
166-
decoded = self.decode_complete(jwt, key, algorithms, options)
168+
decoded = self.decode_complete(jwt, key, algorithms, options, **kwargs)
167169
return decoded["payload"]
168170

169171
def get_unverified_header(self, jwt):

jwt/api_jwt.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ def decode_complete(
6868
key: str = "",
6969
algorithms: List[str] = None,
7070
options: Dict = None,
71-
audience: Optional[Union[str, List[str]]] = None,
72-
issuer: Optional[str] = None,
73-
leeway: Union[float, timedelta] = 0,
71+
**kwargs,
7472
) -> Dict[str, Any]:
7573
if options is None:
7674
options = {"verify_signature": True}
@@ -94,6 +92,7 @@ def decode_complete(
9492
key=key,
9593
algorithms=algorithms,
9694
options=options,
95+
**kwargs,
9796
)
9897

9998
try:
@@ -104,7 +103,7 @@ def decode_complete(
104103
raise DecodeError("Invalid payload string: must be a json object")
105104

106105
merged_options = {**self.options, **options}
107-
self._validate_claims(payload, merged_options, audience, issuer, leeway)
106+
self._validate_claims(payload, merged_options, **kwargs)
108107

109108
decoded["payload"] = payload
110109
return decoded
@@ -115,20 +114,18 @@ def decode(
115114
key: str = "",
116115
algorithms: List[str] = None,
117116
options: Dict = None,
118-
audience: Optional[Union[str, List[str]]] = None,
119-
issuer: Optional[str] = None,
120-
leeway: Union[float, timedelta] = 0,
117+
**kwargs,
121118
) -> Dict[str, Any]:
122-
decoded = self.decode_complete(
123-
jwt, key, algorithms, options, audience, issuer, leeway
124-
)
119+
decoded = self.decode_complete(jwt, key, algorithms, options, **kwargs)
125120
return decoded["payload"]
126121

127-
def _validate_claims(self, payload, options, audience, issuer, leeway):
122+
def _validate_claims(
123+
self, payload, options, audience=None, issuer=None, leeway=0, **kwargs
124+
):
128125
if isinstance(leeway, timedelta):
129126
leeway = leeway.total_seconds()
130127

131-
if not isinstance(audience, (str, type(None), Iterable)):
128+
if not isinstance(audience, (bytes, str, type(None), Iterable)):
132129
raise TypeError("audience must be a string, iterable, or None")
133130

134131
self._validate_required_claims(payload, options)

tests/test_api_jwt.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,6 @@ def test_decode_with_non_mapping_payload_throws_exception(self, jwt):
106106
exception = context.value
107107
assert str(exception) == "Invalid payload string: must be a json object"
108108

109-
def test_decode_with_unknown_parameter_throws_exception(self, jwt):
110-
secret = "secret"
111-
example_jwt = (
112-
b"eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9"
113-
b".eyJoZWxsbyI6ICJ3b3JsZCJ9"
114-
b".tvagLDLoaiJKxOKqpBXSEGy7SYSifZhjntgm9ctpyj8"
115-
)
116-
117-
with pytest.raises(TypeError):
118-
jwt.decode(example_jwt, key=secret, foo="bar", algorithms=["HS256"])
119-
120109
def test_decode_with_invalid_audience_param_throws_exception(self, jwt):
121110
secret = "secret"
122111
example_jwt = (

0 commit comments

Comments
 (0)