Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't accept decode(..., algorithm=...) #446

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jwt/api_jws.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def decode(self,
verify=True, # type: bool
algorithms=None, # type: List[str]
options=None, # type: Dict
**kwargs):
):

merged_options = merge_dict(self.options, options)
verify_signature = merged_options['verify_signature']
Expand Down
22 changes: 13 additions & 9 deletions jwt/api_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ def decode(self,
else:
options.setdefault('verify_signature', verify)

if verify:
verify_options = merge_dict(self.options, options)
audience = kwargs.pop("audience", None)
issuer = kwargs.pop("issuer", None)
leeway = kwargs.pop("leeway", 0)
if "verify_expiration" in kwargs:
verify_options['verify_exp'] = kwargs.pop("verify_expiration", True)
warnings.warn('The verify_expiration parameter is deprecated. '
'Please use verify_exp in options instead.',
DeprecationWarning)

decoded = super(PyJWT, self).decode(
jwt, key=key, algorithms=algorithms, options=options, **kwargs
)
Expand All @@ -101,19 +112,12 @@ def decode(self,
raise DecodeError('Invalid payload string: must be a json object')

if verify:
merged_options = merge_dict(self.options, options)
self._validate_claims(payload, merged_options, **kwargs)
self._validate_claims(payload, verify_options, audience, issuer, leeway)

return payload

def _validate_claims(self, payload, options, audience=None, issuer=None,
leeway=0, **kwargs):

if 'verify_expiration' in kwargs:
options['verify_exp'] = kwargs.get('verify_expiration', True)
warnings.warn('The verify_expiration parameter is deprecated. '
'Please use verify_exp in options instead.',
DeprecationWarning)
leeway=0):

if isinstance(leeway, timedelta):
leeway = leeway.total_seconds()
Expand Down
2 changes: 1 addition & 1 deletion jwt/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
try:
import cryptography
except ImportError:
cryptography = None
cryptography = None # type: ignore # https://github.com/python/mypy/issues/1297

try:
import ecdsa
Expand Down