diff options
author | Jon Dufresne <jon.dufresne@gmail.com> | 2020-12-17 16:31:49 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-17 19:31:49 -0500 |
commit | d0b9dc7e7dc00a8358721dd01c003bfeadb231d2 (patch) | |
tree | 9f65b8e04cd8a01e18c6b77beb9eea761fbe656f | |
parent | d3219c5c2e4dea78955080afaaf251dd3e61bc01 (diff) | |
download | pyjwt-d0b9dc7e7dc00a8358721dd01c003bfeadb231d2.tar.gz |
Prefer direct indexing over options.get() (#552)
Default options are set using PyJWT._get_default_options() therefore,
there should never be a KeyError when indexing options directly. Enforce
this expectation. Also avoids duplicating the default for the "require"
option.
-rw-r--r-- | jwt/api_jwt.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/jwt/api_jwt.py b/jwt/api_jwt.py index 6a7f027..e91fa0a 100644 --- a/jwt/api_jwt.py +++ b/jwt/api_jwt.py @@ -125,23 +125,23 @@ class PyJWT(PyJWS): now = timegm(datetime.utcnow().utctimetuple()) - if "iat" in payload and options.get("verify_iat"): + if "iat" in payload and options["verify_iat"]: self._validate_iat(payload, now, leeway) - if "nbf" in payload and options.get("verify_nbf"): + if "nbf" in payload and options["verify_nbf"]: self._validate_nbf(payload, now, leeway) - if "exp" in payload and options.get("verify_exp"): + if "exp" in payload and options["verify_exp"]: self._validate_exp(payload, now, leeway) - if options.get("verify_iss"): + if options["verify_iss"]: self._validate_iss(payload, issuer) - if options.get("verify_aud"): + if options["verify_aud"]: self._validate_aud(payload, audience) def _validate_required_claims(self, payload, options): - for claim in options.get("require", []): + for claim in options["require"]: if payload.get(claim) is None: raise MissingRequiredClaimError(claim) |