From 4ea896c246a4810f2d9c6bce431ca9f46e290371 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Mon, 27 Oct 2025 19:26:25 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20docstrings=20to=20`enhance?= =?UTF-8?q?ment/support-jwt-multiple-issuers`=20(#2282)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 📝 Add docstrings to `enhancement/support-jwt-multiple-issuers` Docstrings generation was requested by @jlowin. * https://github.com/jlowin/fastmcp/pull/2233#issuecomment-3453446122 The following files were modified: * `src/fastmcp/server/auth/providers/jwt.py` * Fix formatting issues in JWT provider docstrings Co-authored-by: Jeremiah Lowin --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Jeremiah Lowin --- src/fastmcp/server/auth/providers/jwt.py | 32 ++++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/fastmcp/server/auth/providers/jwt.py b/src/fastmcp/server/auth/providers/jwt.py index b03463ee8..1d6f4baa4 100644 --- a/src/fastmcp/server/auth/providers/jwt.py +++ b/src/fastmcp/server/auth/providers/jwt.py @@ -193,19 +193,19 @@ class JWTVerifier(TokenVerifier): base_url: AnyHttpUrl | str | NotSetT | None = NotSet, ): """ - Initialize the JWT token verifier. + Initialize a JWTVerifier configured to validate JWTs using either a static key or a JWKS endpoint. - Args: - public_key: For asymmetric algorithms (RS256, ES256, etc.): PEM-encoded public key. - For symmetric algorithms (HS256, HS384, HS512): The shared secret string. - jwks_uri: URI to fetch JSON Web Key Set (only for asymmetric algorithms) - issuer: Expected issuer claim - audience: Expected audience claim(s) - algorithm: JWT signing algorithm. Supported algorithms: - - Asymmetric: RS256/384/512, ES256/384/512, PS256/384/512 (default: RS256) - - Symmetric: HS256, HS384, HS512 - required_scopes: Required scopes for all tokens - base_url: Base URL for TokenVerifier protocol + Parameters: + public_key (str | NotSetT | None): PEM-encoded public key for asymmetric algorithms or shared secret for symmetric algorithms. + jwks_uri (str | NotSetT | None): URI to fetch a JSON Web Key Set; used when verifying tokens with remote JWKS. + issuer (str | list[str] | NotSetT | None): Expected issuer claim value or list of allowed issuer values. + audience (str | list[str] | NotSetT | None): Expected audience claim value or list of allowed audience values. + algorithm (str | NotSetT | None): JWT signing algorithm to accept (default: "RS256"). Supported: HS256/384/512, RS256/384/512, ES256/384/512, PS256/384/512. + required_scopes (list[str] | NotSetT | None): Scopes that must be present in validated tokens. + base_url (AnyHttpUrl | str | NotSetT | None): Base URL passed to the parent TokenVerifier. + + Raises: + ValueError: If neither or both of `public_key` and `jwks_uri` are provided, or if `algorithm` is unsupported. """ settings = JWTVerifierSettings.model_validate( { @@ -366,13 +366,13 @@ class JWTVerifier(TokenVerifier): async def load_access_token(self, token: str) -> AccessToken | None: """ - Validates the provided JWT bearer token. + Validate a JWT bearer token and return an AccessToken when the token is valid. - Args: - token: The JWT token string to validate + Parameters: + token (str): The JWT bearer token string to validate. Returns: - AccessToken object if valid, None if invalid or expired + AccessToken | None: An AccessToken populated from token claims if the token is valid; `None` if the token is expired, has an invalid signature or format, fails issuer/audience/scope validation, or any other validation error occurs. """ try: # Get verification key (static or from JWKS)