@@ -8,13 +8,15 @@ API Reference
88 Encode the ``payload `` as JSON Web Token.
99
1010 :param dict payload: JWT claims, e.g. ``dict(iss=..., aud=..., sub=...) ``
11- :param str key: a key suitable for the chosen algorithm:
11+ :param key: a key suitable for the chosen algorithm:
1212
1313 * for **asymmetric algorithms **: PEM-formatted private key, a multiline string
1414 * for **symmetric algorithms **: plain string, sufficiently long for security
1515
16+ :type key: str or bytes or jwt.PyJWK
1617 :param str algorithm: algorithm to sign the token with, e.g. ``"ES256" ``.
1718 If ``headers `` includes ``alg ``, it will be preferred to this parameter.
19+ If ``key `` is a :class: `jwt.PyJWK ` object, by default the key algorithm will be used.
1820 :param dict headers: additional JWT header fields, e.g. ``dict(kid="my-key-id") ``.
1921 :param json.JSONEncoder json_encoder: custom JSON encoder for ``payload `` and ``headers ``
2022 :rtype: str
@@ -25,9 +27,11 @@ API Reference
2527 Verify the ``jwt `` token signature and return the token claims.
2628
2729 :param str jwt: the token to be decoded
28- :param str key: the key suitable for the allowed algorithm
30+ :param key: the key suitable for the allowed algorithm
31+ :type key: str or bytes or jwt.PyJWK
2932
3033 :param list algorithms: allowed algorithms, e.g. ``["ES256"] ``
34+ If ``key `` is a :class: `jwt.PyJWK ` object, allowed algorithms will default to the key algorithm.
3135
3236 .. warning ::
3337
@@ -70,6 +74,54 @@ API Reference
7074 :rtype: dict
7175 :returns: the JWT claims
7276
77+ .. class :: PyJWK
78+
79+ A class that represents a `JSON Web Key <https://www.rfc-editor.org/rfc/rfc7517 >`_.
80+
81+ .. method :: __init__(self, jwk_data, algorithm=None)
82+
83+ :param dict data: The decoded JWK data.
84+ :param algorithm: The key algorithm. If not specific, the key's ``alg `` will be used.
85+ :type algorithm: str or None
86+
87+ .. staticmethod :: from_json(data, algorithm=None)
88+
89+ :param str data: The JWK data, as a JSON string.
90+ :param algorithm: The key algorithm. If not specific, the key's ``alg `` will be used.
91+ :type algorithm: str or None
92+
93+ :returntype: jwt.PyJWK
94+
95+ Create a :class: `jwt.PyJWK ` object from a JSON string.
96+
97+ .. property :: algorithm_name
98+
99+ :type: str
100+
101+ The name of the algorithm used by the key.
102+
103+ .. property :: Algorithm
104+
105+ The ``Algorithm `` class associated with the key.
106+
107+ .. property :: key_type
108+
109+ :type: str or None
110+
111+ The ``kty `` property from the JWK.
112+
113+ .. property :: key_id
114+
115+ :type: str or None
116+
117+ The ``kid `` property from the JWK.
118+
119+ .. property :: public_key_use
120+
121+ :type: str or None
122+
123+ The ``use `` property from the JWK.
124+
73125.. module :: jwt.api_jwt
74126
75127.. function :: decode_complete(jwt, key="", algorithms=None, options=None, audience=None, issuer=None, leeway=0)
0 commit comments