From 8f5dfd04507723996edbf2f1689995e684173836 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 12 Sep 2024 22:10:50 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/usage.rst | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index ffda3b11..efae248b 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -159,7 +159,9 @@ you can set a leeway of 10 seconds in order to have some margin: >>> import time, datetime >>> from datetime import timezone - >>> payload = {"exp": datetime.datetime.now(tz=timezone.utc) + datetime.timedelta(seconds=1)} + >>> payload = { + ... "exp": datetime.datetime.now(tz=timezone.utc) + datetime.timedelta(seconds=1) + ... } >>> token = jwt.encode(payload, "secret") >>> time.sleep(2) >>> # JWT payload is now expired @@ -250,7 +252,9 @@ If multiple audiences are accepted, the ``audience`` parameter for >>> payload = {"some": "payload", "aud": "urn:foo"} >>> token = jwt.encode(payload, "secret") - >>> decoded = jwt.decode(token, "secret", audience=["urn:foo", "urn:bar"], algorithms=["HS256"]) + >>> decoded = jwt.decode( + ... token, "secret", audience=["urn:foo", "urn:bar"], algorithms=["HS256"] + ... ) >>> try: ... jwt.decode(token, "secret", audience=["urn:invalid"], algorithms=["HS256"]) ... except jwt.InvalidAudienceError: @@ -284,9 +288,14 @@ If you wish to require one or more claims to be present in the claimset, you can .. code-block:: pycon - >>> token = jwt.encode({"sub":"1234567890","iat":1371720939}, "secret") + >>> token = jwt.encode({"sub": "1234567890", "iat": 1371720939}, "secret") >>> try: - ... jwt.decode(token, "secret", options={"require": ["exp", "iss", "sub"]}, algorithms=["HS256"]) + ... jwt.decode( + ... token, + ... "secret", + ... options={"require": ["exp", "iss", "sub"]}, + ... algorithms=["HS256"], + ... ) ... except jwt.MissingRequiredClaimError as e: ... print(e) ... @@ -340,7 +349,9 @@ is not built into pyjwt. # example of fetching data from your OIDC server # see: https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfig oidc_server = ... - oidc_config = requests.get(f"https://{oidc_server}/.well-known/openid-configuration").json() + oidc_config = requests.get( + f"https://{oidc_server}/.well-known/openid-configuration" + ).json() signing_algos = oidc_config["id_token_signing_alg_values_supported"] # setup a PyJWKClient to get the appropriate signing key