Skip to content

Commit

Permalink
Add API docs for PyJWK. (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
luhn authored Oct 7, 2024
1 parent f6369b9 commit d45cda6
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ API Reference
Encode the ``payload`` as JSON Web Token.

:param dict payload: JWT claims, e.g. ``dict(iss=..., aud=..., sub=...)``
:param str key: a key suitable for the chosen algorithm:
:param key: a key suitable for the chosen algorithm:

* for **asymmetric algorithms**: PEM-formatted private key, a multiline string
* for **symmetric algorithms**: plain string, sufficiently long for security

:type key: str or bytes or jwt.PyJWK
:param str algorithm: algorithm to sign the token with, e.g. ``"ES256"``.
If ``headers`` includes ``alg``, it will be preferred to this parameter.
If ``key`` is a :class:`jwt.PyJWK` object, by default the key algorithm will be used.
:param dict headers: additional JWT header fields, e.g. ``dict(kid="my-key-id")``.
:param json.JSONEncoder json_encoder: custom JSON encoder for ``payload`` and ``headers``
:rtype: str
Expand All @@ -25,9 +27,11 @@ API Reference
Verify the ``jwt`` token signature and return the token claims.

:param str jwt: the token to be decoded
:param str key: the key suitable for the allowed algorithm
:param key: the key suitable for the allowed algorithm
:type key: str or bytes or jwt.PyJWK

:param list algorithms: allowed algorithms, e.g. ``["ES256"]``
If ``key`` is a :class:`jwt.PyJWK` object, allowed algorithms will default to the key algorithm.

.. warning::

Expand Down Expand Up @@ -70,6 +74,54 @@ API Reference
:rtype: dict
:returns: the JWT claims

.. class:: PyJWK

A class that represents a `JSON Web Key <https://www.rfc-editor.org/rfc/rfc7517>`_.

.. method:: __init__(self, jwk_data, algorithm=None)

:param dict data: The decoded JWK data.
:param algorithm: The key algorithm. If not specific, the key's ``alg`` will be used.
:type algorithm: str or None

.. staticmethod:: from_json(data, algorithm=None)

:param str data: The JWK data, as a JSON string.
:param algorithm: The key algorithm. If not specific, the key's ``alg`` will be used.
:type algorithm: str or None

:returntype: jwt.PyJWK

Create a :class:`jwt.PyJWK` object from a JSON string.

.. property:: algorithm_name

:type: str

The name of the algorithm used by the key.

.. property:: Algorithm

The ``Algorithm`` class associated with the key.

.. property:: key_type

:type: str or None

The ``kty`` property from the JWK.

.. property:: key_id

:type: str or None

The ``kid`` property from the JWK.

.. property:: public_key_use

:type: str or None

The ``use`` property from the JWK.

.. module:: jwt.api_jwt

.. function:: decode_complete(jwt, key="", algorithms=None, options=None, audience=None, issuer=None, leeway=0)
Expand Down

0 comments on commit d45cda6

Please sign in to comment.