Debian Codegraph @

jwt/types.py

raw
1 from typing import Any, Callable, TypedDict
2
3 JWKDict = dict[str, Any]
4
5 HashlibHash = Callable[..., Any]
6
7
8 class SigOptions(TypedDict, total=False):
9 """Options for PyJWS class (TypedDict). Note that this is a smaller set of options than
10 for :py:func:`jwt.decode()`."""
11
12 verify_signature: bool
13 """verify the JWT cryptographic signature"""
14 enforce_minimum_key_length: bool
15 """Default: ``False``. Raise :py:class:`jwt.exceptions.InvalidKeyError` instead of warning when keys are below minimum recommended length."""
16
17
18 class Options(TypedDict, total=False):
19 """Options for :py:func:`jwt.decode()` and :py:func:`jwt.decode_complete()` (TypedDict).
20
21 .. warning::
22
23 Some claims, such as ``exp``, ``iat``, ``jti``, ``nbf``, and ``sub``,
24 will only be verified if present. Please refer to the documentation below
25 for which ones, and make sure to include them in the ``require`` param
26 if you want to make sure that they are always present (and therefore always verified
27 if ``verify_{claim} = True`` for that claim).
28 """
29
30 verify_signature: bool
31 """Default: ``True``. Verify the JWT cryptographic signature."""
32 require: list[str]
33 """Default: ``[]``. List of claims that must be present.
34 Example: ``require=["exp", "iat", "nbf"]``.
35 **Only verifies that the claims exists**. Does not verify that the claims are valid."""
36 strict_aud: bool
37 """Default: ``False``. (requires ``verify_aud=True``) Check that the ``aud`` claim is a single value (not a list), and matches ``audience`` exactly."""
38 verify_aud: bool
39 """Default: ``verify_signature``. Check that ``aud`` (audience) claim matches ``audience``."""
40 verify_exp: bool
41 """Default: ``verify_signature``. Check that ``exp`` (expiration) claim value is in the future (if present in payload). """
42 verify_iat: bool
43 """Default: ``verify_signature``. Check that ``iat`` (issued at) claim value is an integer (if present in payload). """
44 verify_iss: bool
45 """Default: ``verify_signature``. Check that ``iss`` (issuer) claim matches ``issuer``. """
46 verify_jti: bool
47 """Default: ``verify_signature``. Check that ``jti`` (JWT ID) claim is a string (if present in payload). """
48 verify_nbf: bool
49 """Default: ``verify_signature``. Check that ``nbf`` (not before) claim value is in the past (if present in payload). """
50 verify_sub: bool
51 """Default: ``verify_signature``. Check that ``sub`` (subject) claim is a string and matches ``subject`` (if present in payload). """
52 enforce_minimum_key_length: bool
53 """Default: ``False``. Raise :py:class:`jwt.exceptions.InvalidKeyError` instead of warning when keys are below minimum recommended length."""
54
55
56 # The only difference between Options and FullOptions is that FullOptions
57 # required _every_ value to be there; Options doesn't require any
58 class FullOptions(TypedDict):
59 verify_signature: bool
60 require: list[str]
61 strict_aud: bool
62 verify_aud: bool
63 verify_exp: bool
64 verify_iat: bool
65 verify_iss: bool
66 verify_jti: bool
67 verify_nbf: bool
68 verify_sub: bool
69 enforce_minimum_key_length: bool