summaryrefslogtreecommitdiff
path: root/jwt/api_jwt.py
Commit message (Collapse)AuthorAgeFilesLines
* Add complete types to take all allowed keys into account (#873)Viicos2023-04-161-32/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Use new style typing * Fix type annotations to allow all keys * Use string type annotations where required * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove outdated comment * Ignore `if TYPE_CHECKING:` lines in coverage * Remove duplicate test * Fix mypy errors * Update algorithms.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fully switch to modern annotations * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update `pre-commit` mypy config * Use Python 3.11 for mypy * Update mypy Python version in `pyproject.toml` * Few tests mypy fixes * fix mypy errors on tests * Fix key imports * Remove unused import * Fix randomly failing test --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
* Make `Algorithm` an abstract base class (#845)Viicos2023-03-061-4/+4
| | | | | | | | | | | * Make `Algorithm` an abstract base class This also removes some tests that are not relevant anymore Raise `NotImplementedError` for `NoneAlgorithm` * Use `hasattr` instead of `getattr` * Only allow `dict` in `encode`
* Fix `_validate_iat` validation (#847)Viicos2023-01-141-2/+1
| | | | | * Fix `_validate_iat` validation * Add test and update changelog
* Differentiate between two errors (#809)Maxim2023-01-031-1/+1
| | | | | * Differentiate between two errors * #809 mention in the changelog
* Make mypy configuration stricter and improve typing (#830)Aarni Koskela2022-12-101-14/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * PyJWS._verify_signature: raise early KeyError if header is missing alg * Make Mypy configuration stricter * Improve typing in jwt.utils * Improve typing in jwt.help * Improve typing in jwt.exceptions * Improve typing in jwt.api_jwk * Improve typing in jwt.api_jws * Improve typing & clean up imports in jwt.algorithms * Correct JWS.decode rettype to any (payload could be something else) * Update typing in api_jwt * Improve typing in jwks_client * Improve typing in docs/conf.py * Fix (benign) mistyping in test_advisory * Fix misc type complaints in tests
* Add `sort_headers` parameter to `api_jwt.encode` (#832)Erik Vroon2022-12-081-1/+9
| | | | | | | | | | | | | | | | | | | | | | | * Add `sort_headers` parameter to `api_jwt.encode` This allows you to not sort headers, which prevents a breaking change between v2.4.0 and v2.5.0 * Add `test_sorting_headers` test * Remove outdated comment about misordered headers * Explicity assert sorting in `test_sorting_of_headers` * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Parametrize `test_sorting_of_headers` * Use normal dict in `test_sorting_of_headers` * fixup! Use normal dict in `test_sorting_of_headers` Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add PyJWT._{de,en}code_payload hooks (#829)Aarni Koskela2022-12-081-9/+40
| | | | | * Add PyJWT._decode_payload hook * Add PyJWT._encode_payload hook
* fix: use datetime.datetime.timestamp function to have a milliseconds (#821)François Dailloux2022-11-051-1/+1
| | | Fixes #814
* Handling 'ImmatureSignatureError' for issued_at time (#794)Sriharan Manogaran2022-10-151-1/+4
| | | | | * Handling 'ImmatureSignatureError' for issued_at time when it is a future time * adding changelog and test cases
* Invalidate exp when exp == now() (#797)William Edmisten2022-09-231-1/+1
| | | | | * Invalidate exp when exp == now() * Update changelog
* Update audience typing (#782)Julian Maurin2022-07-311-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | * fix(api_jwt): update audience typing & type checking * doc(api): update decode.audience typing * feat(test_api_jwt): ensure audience as bytes raises error * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * refacto(api_jwt): precise typing Co-authored-by: Julian Maurin <julian.maurin.perso@pm.me> Update jwt/api_jwt.py Co-authored-by: Julian Maurin <julian.maurin.perso@pm.me> fix(jwt/api_jwt.py): backport future annotations * fix: handle audience=0 Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
* Emit a deprecation warning for unsupported kwargs (#776)Stephen Rosen2022-07-051-7/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `**kwargs` usages cannot be removed without breaking backwards compatibility. Unsupported kwargs cannot even be rejected without breaking compatibility. However, this does not mean that the library cannot identify and warn when unsupported arguments are used. The warning behavior simply has to be separated from any removal of `**kwargs`. All legitimate `**kwargs` usages have been replaced with explicit arguments. Any other arguments will be captured under `**kwargs` and trigger the deprecation warnings. In the cases of `decode() -> decode_complete()` passthrough, the passthrough has been removed to avoid duplicate deprecation warnings on a single usage. This makes a very subtle behavioral change to `**kwargs` *only* for the case of a subclass of PyJWT or PyJWS. Extra arguments used by a specialized subclass won't pass through transparently anymore. In such a case the subclass author has multiple resolutions available, including reimplementation of the `decode()` method to passthrough the additional argument. Although technically backwards-incompatible for a niche subclassing usage, this behavior is very nearly identical and shouldn't pose an issue for the vast majority of pyjwt users. The deprecation warning does not cover all deprecated usages. In particular, several passthrough arguments for claim validation should probably be made available via `options` and later removed. The arguments in need of attention now have inline comments in the signature definitions, but are otherwise left unmodified, leaving current usages correct and valid.
* Fixes for pyright on strict mode (#747)Brandon Chinn2022-05-311-3/+3
| | | | | * Fixes for pyright on strict mode * Update CHANGELOG.rst
* Revert "adding support for compressed payloads (#753)" (#761)Asif Saif Uddin2022-05-231-22/+1
| | | This reverts commit 675fa10db578886ee6cfd1df688236f69560ced4.
* adding support for compressed payloads (#753)Daniel Miles2022-05-191-1/+22
| | | | | | | | | | | | | | | | | | | * adding support for compressed payloads * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * adding test to cover all lines in patch * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * addressing flake8 unused variable and cyclomatic complexity complaints * expanding test for better coverage Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Replace various string interpolations with f-strings (#744)Aarni Koskela2022-04-121-1/+1
|
* Don't mutate options dictionary in .decode_complete() (#743)Aarni Koskela2022-04-051-4/+2
| | | Fixes #679
* Add a deprecation warning when jwt.decode() is called with the legacy ↵Aarni Koskela2022-04-051-0/+12
| | | | | | | verify= argument (#742) Since the arbitrary/unused `**kwargs` can't quite be dropped (as #657 would do) without a major version bump (as reverted in #701), it's still a good idea to warn users if they are attempting to use contradictory arguments for the security-sensitive `verify=` argument.
* Don't use implicit optionals (#705)Kyungmin Lee2021-10-221-4/+4
| | | | | | | | | | | | | * Turn off implicit-optional * Change type annotations to use explicit optional According to PEP 484, implicit Optional is no longer recommended. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Revert "Remove arbitrary kwargs. (#657)" (#701)Asif Saif Uddin2021-10-151-12/+9
| | | This reverts commit 5fe7f2b28ffcd27a3e520be750858944889112ef.
* Use timezone package as Python 3.5+ is required (#694)Kevin Kirsche2021-10-061-2/+2
| | | | | | | | | | | | | | | | | | | * Use timezone package as Python 3.5+ is required This method is deprecated: https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow Replaced with: https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow using: https://docs.python.org/3/library/datetime.html#datetime.timezone.utc which seems to indicate this was added in Python 3.2 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Chore: inline Variables that immediately Returned (#690)Yasser Tahiri2021-10-031-1/+1
| | | | | * Fix Inline variables & Refactor Code Expression * Fix Linting Issue
* Remove arbitrary kwargs. (#657)Ajitomi, Daisuke2021-08-081-9/+12
| | | | | * Remove arbitrary kwargs. * Update CHANGELOG.
* Prefer headers['alg'] to algorithm parameter in encode(). (#673)Ajitomi, Daisuke2021-08-051-1/+1
| | | | | | | | | | | * Prefer headers['alg'] to algorithm parameter in encode(). * Fix lack of @crypto_required. * Prefer headers['alg'] to algorithm parameter in encode(). * Prefer headers['alg'] to algorithm parameter in encode(). * Make algorithm parameter of encode() Optioanl explicitly.
* Fix aud validation to support {'aud': null} case. (#670)Ajitomi, Daisuke2021-07-301-8/+7
| | | | | * Fix aud validation to support {'aud': null} case. * Fix aud validation to support {'aud': null} case.
* Validate claims if configured and verify_signature is not. (#608)Rémy HUBSCHER2021-02-151-3/+9
| | | | | | | * Validate claims if configured. * Remove secret and algorithm since we don't validate the signature. * Add changelog.
* Simplify black configuration to be closer to upstream defaults (#568)Jon Dufresne2020-12-211-12/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Simplify black configuration to be closer to upstream defaults Avoid extra configuration by simply going with Black defaults. This allows removing some configuration options, thus simplifying the overall configuration. It also makes the code style closer to community conventions. As more projects adopt black formatting, more code will look like the black defaults. Further, the default 88 tends to create more readable lines, IMO. The black rationale is located at: https://black.readthedocs.io/en/stable/the_black_code_style.html#line-length * Update tests/test_api_jws.py Co-authored-by: José Padilla <jpadilla@webapplicate.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update tests/test_api_jws.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: José Padilla <jpadilla@webapplicate.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Split PyJWT/PyJWS classes to tighten type interfaces (#559)Jon Dufresne2020-12-191-21/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | The class PyJWT was previously a subclass of PyJWS. However, this combination does not follow the Liskov substitution principle. That is, using PyJWT in place of a PyJWS would not produce correct results or follow type contracts. While these classes look to share a common interface it doesn't go beyond the method names "encode" and "decode" and so is merely superficial. The classes have been split into two. PyJWT now uses composition instead of inheritance to achieve the desired behavior. Splitting the classes in this way allowed for precising the type interfaces. The complete parameter to .decode() has been removed. This argument was used to alter the return type of .decode(). Now, there are two different methods with more explicit return types and values. The new method name is .decode_complete(). This fills the previous role filled by .decode(..., complete=True). Closes #554, #396, #394 Co-authored-by: Sam Bull <git@sambull.org> Co-authored-by: Sam Bull <git@sambull.org>
* Do not mutate the input payload in PyJWT.encode() (#557)Jon Dufresne2020-12-191-0/+1
|
* Tighten type checking of string values (#556)Jon Dufresne2020-12-171-3/+3
| | | In Python 3, these values will always be str.
* Replace merge_dict() with builtin dict unpacking generalizations (#555)Jon Dufresne2020-12-171-2/+1
| | | | | | | | Merging two dict is support since Python 3.5 using the ** syntax. See: - https://docs.python.org/3.9/whatsnew/3.5.html#whatsnew-pep-448 - https://www.python.org/dev/peps/pep-0448/
* Prefer direct indexing over options.get() (#552)Jon Dufresne2020-12-171-6/+6
| | | | | | 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.
* Cleanup "noqa" comments (#553)Jon Dufresne2020-12-171-1/+0
| | | | - Remove "noqa" comments that are unnecessary - Remove unused imports from api_jwt.py
* Enforce .encode() return type using mypy (#551)Jon Dufresne2020-12-171-1/+1
| | | Closes #505
* Remove unnecessary Unicode decoding before json.loads() (#542)Jon Dufresne2020-12-161-2/+2
| | | | | | | | Since Python 3.6, json.loads() accepts both Unicode and byte strings. https://docs.python.org/3/library/json.html#json.loads > Changed in version 3.6: s can now be of type bytes or bytearray. The > input encoding should be UTF-8, UTF-16 or UTF-32.
* Upgrade black version and usage (#538)Jon Dufresne2020-12-161-2/+2
| | | | | | Upgrade black to version 20.8b1 and specify that Python 3.6+ syntax should be used. Run it on all files to upgrade syntax.
* Update typing syntax and usage for Python 3.6+ (#535)Jon Dufresne2020-12-161-20/+14
| | | | | | | | | | | | | | | | | | Now that Python 2 is not supported, can move away from type comments to type annotation 🎉. The typing module is always available, so remove the guards. Specify the supported Python in the mypy configuration. Move other mypy configurations to one place. This way, whether tox is used or not, the same mypy errors appear. Distribute and install PEP-561 compliant py.typed file. When PyJWT is a imported as a library, this tells mypy to use the provided type annotations rather than going through typeshed. This way, the types are always up to date when running mypy. Remove outdated ignores since dropping Python 2.
* Avoid loading token twice in pyjwt.decode (#506)Federico Caselli2020-12-121-2/+0
| | | Removes a call to _load that was unused.
* Drop deprecation warnings (#515)José Padilla2020-08-241-46/+11
| | | | | | | | | | | * Drop deprecation warnings * Add missing keys * Remove commented exceptions * Undo lambda change * Remove unused keys
* Introduce better experience for JWKs (#511)José Padilla2020-08-241-2/+15
| | | | | | | | | | | * Introduce better experience for JWKs * Remove explicit inheritance * Add tests for PyJWK * Fix failing test * Get rid of lambda
* Remove unnecessary compatibility shims for Python 2 (#498)Jon Dufresne2020-06-191-6/+6
| | | | | | | | | | | As the project is Python 3 only, can remove the compatibility shims in compat.py. Type checking has been simplified where it can: - str is iterable - bytes is iterable - use isinstance instead of issubclass The remaining function bytes_from_int() has been moved to utils.py.
* Emit warnings about user code, not pyjwt code (#494)Marius Gedminas2020-06-091-0/+3
| | | | This assumes all direct calls to private methods (leading underscore in name) are from pyjwt code, hence stacklevel=3 nor 2.
* Run pyupgrade across project to use modern Python 3 conventions (#491)Jon Dufresne2020-06-081-3/+3
| | | | | | | | pyupgrade is a tool to automatically upgrade Python syntax for newer versions of the language. Running pyupgrade removes several Python-2-isms that are no longer necessary now that the project is Python 3 only. https://github.com/asottile/pyupgrade
* Require tweak (#280)Pau Ruiz Safont2020-05-141-12/+22
| | | | | | | | | | | * Use require options as a list, instead of booleans Deprecate the use of the boolean options * Add test for the new require option * Add documentation on how to use the require option Co-authored-by: Pau Ruiz i Safont <psafont@ebi.ac.uk>
* DX Tweaks (#450)José Padilla2019-10-211-91/+107
| | | | | | | | | | * Setup pre-commit hooks * Run initial `tox -e lint` * Fix package name * Fix .travis.yml
* Correct type for json_encoder argument (#438)Jon Dufresne2019-09-281-2/+2
| | | | | | | | | | | Per recent upstream fix to typeshed, json.dumps() cls argument should be optional type JSONEncoder. https://github.com/python/typeshed/commit/8e0d288ea49a34f9bd21b1598ec487414a339a1f Fixes mypy error: jwt/api_jws.py:102: error: Argument "cls" to "dumps" has incompatible type "Optional[Callable[..., Any]]"; expected "Optional[Type[JSONEncoder]]" jwt/api_jwt.py:61: error: Argument "cls" to "dumps" has incompatible type "Optional[Callable[..., Any]]"; expected "Optional[Type[JSONEncoder]]"
* Decode return type is dict[str, Any] (#393)Jacopo Farina2019-01-311-2/+3
| | | | | | * Use Dict instead of Mapping for return type of decode * Use str as a dictionary key
* Import collection ABC's from correct module (#384)Tsuyoshi Hombashi2018-11-251-6/+1
| | | | | | * Move ABCs imports to compat.py to reuse the imports from other modules * Import collection ABC's from correct module
* Support Python 3.7 (#375)kreutz-hs2018-11-021-1/+5
| | | | | * Import collection ABC's from correct module They were moved into collections.abc in 3.3 and will be deprecated from collections in 3.8.
* Fix #351 by reverting argument name changes for .decode() (#352)1.6.4Mark Adams2018-05-231-3/+3
| | | | | | * Fix #351 by reverting argument name changes for .decode() * Update CHANGELOG and bump version to 1.6.4