fix(auth): silence authlib.jose DeprecationWarning at JWT import (#4100)

Co-authored-by: Jeremiah Lowin <153965+jlowin@users.noreply.github.com>
This commit is contained in:
Sarthak Bhardwaj 2026-05-07 20:57:08 +05:30 committed by GitHub
commit aaff9243a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 4 deletions

View file

@ -9,10 +9,23 @@ from __future__ import annotations
import base64
import time
import warnings
from typing import Any, overload
from authlib.jose import JsonWebToken
from authlib.jose.errors import JoseError
with warnings.catch_warnings():
# authlib.jose emits AuthlibDeprecationWarning on import; suppress it so
# importing this module does not trigger the warning under
# `warnings.simplefilter("error")`. The `authlib.deprecate` import lives
# inside this block too: importing it for the first time runs
# `warnings.simplefilter("always", AuthlibDeprecationWarning)` at module
# scope, which would otherwise leak past `catch_warnings()` and clobber
# the caller's filter for subsequent Authlib deprecations. See
# jlowin/fastmcp#4098.
from authlib.deprecate import AuthlibDeprecationWarning
warnings.simplefilter("ignore", AuthlibDeprecationWarning)
from authlib.jose import JsonWebToken
from authlib.jose.errors import JoseError
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC

View file

@ -5,12 +5,26 @@ from __future__ import annotations
import contextlib
import json
import time
import warnings
from dataclasses import dataclass
from typing import Any, cast
import httpx
from authlib.jose import JsonWebKey, JsonWebToken
from authlib.jose.errors import JoseError
with warnings.catch_warnings():
# authlib.jose emits AuthlibDeprecationWarning on import; suppress it so
# importing this provider does not trigger the warning under
# `warnings.simplefilter("error")`. The `authlib.deprecate` import lives
# inside this block too: importing it for the first time runs
# `warnings.simplefilter("always", AuthlibDeprecationWarning)` at module
# scope, which would otherwise leak past `catch_warnings()` and clobber
# the caller's filter for subsequent Authlib deprecations. See
# jlowin/fastmcp#4098.
from authlib.deprecate import AuthlibDeprecationWarning
warnings.simplefilter("ignore", AuthlibDeprecationWarning)
from authlib.jose import JsonWebKey, JsonWebToken
from authlib.jose.errors import JoseError
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from pydantic import AnyHttpUrl, SecretStr