π The fast, Pythonic way to build MCP servers and clients.
fix(auth): expose identity assertions on OAuth provider wrappers (#6006)
Jeff Smith4f40ac0defad
diff --git a/fastmcp_slim/fastmcp/server/auth/providers/auth0.py b/fastmcp_slim/fastmcp/server/auth/providers/auth0.pyindex 29cc02a88..1168bf92e 100644--- a/fastmcp_slim/fastmcp/server/auth/providers/auth0.py+++ b/fastmcp_slim/fastmcp/server/auth/providers/auth0.py@@ -46,6 +46,7 @@ from starlette.responses import JSONResponsefrom starlette.routing import Routefrom fastmcp.server.auth import RemoteAuthProvider, TokenVerifier+from fastmcp.server.auth.identity_assertion import IdentityAssertionfrom fastmcp.server.auth.oidc_proxy import (DEFAULT_OIDC_DISCOVERY_TIMEOUT_SECONDS,OIDCConfiguration,@@ -105,6 +106,7 @@ class Auth0Provider(OIDCProxy):fastmcp_access_token_expiry_seconds: int | None = None,token_expiry_threshold_seconds: int = 0,enable_cimd: bool = True,+ identity_assertion: IdentityAssertion | None = None,) -> None:"""Initialize Auth0 OAuth provider.@@ -152,6 +154,8 @@ class Auth0Provider(OIDCProxy):treat a token as expired, refreshing early to avoid races. Defaults to 0.enable_cimd: Enable CIMD (Client ID Metadata Document) support for URL-basedclient IDs (default True). Set to False to disable.+ identity_assertion: Optional SEP-990 ID-JAG configuration for+ identity-bound token exchange. Disabled by default."""# Parse scopes if provided as stringauth0_required_scopes = (@@ -179,6 +183,7 @@ class Auth0Provider(OIDCProxy):fastmcp_access_token_expiry_seconds=fastmcp_access_token_expiry_seconds,token_expiry_threshold_seconds=token_expiry_threshold_seconds,enable_cimd=enable_cimd,+ identity_assertion=identity_assertion,)logger.debug(diff --git a/fastmcp_slim/fastmcp/server/auth/providers/aws.py b/fastmcp_slim/fastmcp/server/auth/providers/aws.pyindex 553c9b705..d715c9f6f 100644--- a/fastmcp_slim/fastmcp/server/auth/providers/aws.py+++ b/fastmcp_slim/fastmcp/server/auth/providers/aws.py@@ -29,6 +29,7 @@ from key_value.aio.protocols import AsyncKeyValuefrom pydantic import AnyHttpUrlfrom fastmcp.server.auth.auth import AccessToken+from fastmcp.server.auth.identity_assertion import IdentityAssertionfrom fastmcp.server.auth.oidc_proxy import (DEFAULT_OIDC_DISCOVERY_TIMEOUT_SECONDS,OIDCProxy,@@ -145,6 +146,7 @@ class AWSCognitoProvider(OIDCProxy):fastmcp_access_token_expiry_seconds: int | None = None,token_expiry_threshold_seconds: int = 0,enable_cimd: bool = True,+ identity_assertion: IdentityAssertion | None = None,):"""Initialize AWS Cognito OAuth provider.@@ -192,6 +194,8 @@ class AWSCognitoProvider(OIDCProxy):treat a token as expired, refreshing early to avoid races. Defaults to 0.enable_cimd: Enable CIMD (Client ID Metadata Document) support for URL-basedclient IDs (default True). Set to False to disable.+ identity_assertion: Optional SEP-990 ID-JAG configuration for+ identity-bound token exchange. Disabled by default."""# Parse scopes if provided as stringrequired_scopes_final = (@@ -228,6 +232,7 @@ class AWSCognitoProvider(OIDCProxy):fastmcp_access_token_expiry_seconds=fastmcp_access_token_expiry_seconds,token_expiry_threshold_seconds=token_expiry_threshold_seconds,enable_cimd=enable_cimd,+ identity_assertion=identity_assertion,)logger.debug(diff --git a/fastmcp_slim/fastmcp/server/auth/providers/azure.py b/fastmcp_slim/fastmcp/server/auth/providers/azure.pyindex 25b9b741a..fcae428d9 100644--- a/fastmcp_slim/fastmcp/server/auth/providers/azure.py+++ b/fastmcp_slim/fastmcp/server/auth/providers/azure.py@@ -15,6 +15,7 @@ from key_value.aio.protocols import AsyncKeyValuefrom fastmcp.dependencies import Dependencyfrom fastmcp.server.auth.auth import MultiAuth+from fastmcp.server.auth.identity_assertion import IdentityAssertionfrom fastmcp.server.auth.oauth_proxy import OAuthProxyfrom fastmcp.server.auth.providers.jwt import JWTVerifierfrom fastmcp.utilities.auth import decode_jwt_payload, parse_scopes@@ -123,6 +124,7 @@ class AzureProvider(OAuthProxy):extra_authorize_params: dict[str, str] | None = None,http_client: httpx2.AsyncClient | None = None,enable_cimd: bool = True,+ identity_assertion: IdentityAssertion | None = None,) -> None:"""Initialize Azure OAuth provider.@@ -199,6 +201,8 @@ class AzureProvider(OAuthProxy):refresh gracefully (e.g. `mcp-remote`). See `OAuthProxy` for details.token_expiry_threshold_seconds: Number of seconds before actual expiry totreat a token as expired, refreshing early to avoid races. Defaults to 0.+ identity_assertion: Optional SEP-990 ID-JAG configuration for+ identity-bound token exchange. Disabled by default."""# Parse scopes if provided as stringparsed_required_scopes = parse_scopes(required_scopes)@@ -295,6 +299,7 @@ class AzureProvider(OAuthProxy):extra_authorize_params=extra_authorize_params,valid_scopes=parsed_required_scopes,enable_cimd=enable_cimd,+ identity_assertion=identity_assertion,)authority_info = ""diff --git a/fastmcp_slim/fastmcp/server/auth/providers/clerk.py b/fastmcp_slim/fastmcp/server/auth/providers/clerk.pyindex 1002646ef..ba3324ce1 100644--- a/fastmcp_slim/fastmcp/server/auth/providers/clerk.py+++ b/fastmcp_slim/fastmcp/server/auth/providers/clerk.py@@ -37,6 +37,7 @@ from pydantic import AnyHttpUrlfrom fastmcp.server.auth import TokenVerifierfrom fastmcp.server.auth.auth import AccessToken+from fastmcp.server.auth.identity_assertion import IdentityAssertionfrom fastmcp.server.auth.oauth_proxy import OAuthProxyfrom fastmcp.utilities.auth import parse_scopesfrom fastmcp.utilities.logging import get_logger@@ -305,6 +306,7 @@ class ClerkProvider(OAuthProxy):extra_authorize_params: dict[str, str] | None = None,http_client: httpx2.AsyncClient | None = None,enable_cimd: bool = True,+ identity_assertion: IdentityAssertion | None = None,):"""Initialize Clerk OAuth provider.@@ -359,6 +361,8 @@ class ClerkProvider(OAuthProxy):refresh gracefully (e.g. `mcp-remote`). See `OAuthProxy` for details.token_expiry_threshold_seconds: Number of seconds before actual expiry totreat a token as expired, refreshing early to avoid races. Defaults to 0.+ identity_assertion: Optional SEP-990 ID-JAG configuration for+ identity-bound token exchange. Disabled by default."""domain = _normalize_domain(domain)@@ -407,6 +411,7 @@ class ClerkProvider(OAuthProxy):extra_authorize_params=extra_authorize_params_final or None,valid_scopes=parsed_valid_scopes,enable_cimd=enable_cimd,+ identity_assertion=identity_assertion,)logger.debug(diff --git a/fastmcp_slim/fastmcp/server/auth/providers/discord.py b/fastmcp_slim/fastmcp/server/auth/providers/discord.pyindex 8a6b657b6..a00591e91 100644--- a/fastmcp_slim/fastmcp/server/auth/providers/discord.py+++ b/fastmcp_slim/fastmcp/server/auth/providers/discord.py@@ -32,6 +32,7 @@ from pydantic import AnyHttpUrlfrom fastmcp.server.auth import TokenVerifierfrom fastmcp.server.auth.auth import AccessToken+from fastmcp.server.auth.identity_assertion import IdentityAssertionfrom fastmcp.server.auth.oauth_proxy import OAuthProxyfrom fastmcp.utilities.auth import parse_scopesfrom fastmcp.utilities.logging import get_logger@@ -213,6 +214,7 @@ class DiscordProvider(OAuthProxy):token_expiry_threshold_seconds: int = 0,http_client: httpx2.AsyncClient | None = None,enable_cimd: bool = True,+ identity_assertion: IdentityAssertion | None = None,):"""Initialize Discord OAuth provider.@@ -261,6 +263,8 @@ class DiscordProvider(OAuthProxy):refresh gracefully (e.g. `mcp-remote`). See `OAuthProxy` for details.token_expiry_threshold_seconds: Number of seconds before actual expiry totreat a token as expired, refreshing early to avoid races. Defaults to 0.+ identity_assertion: Optional SEP-990 ID-JAG configuration for+ identity-bound token exchange. Disabled by default."""# Parse scopes if provided as stringrequired_scopes_final = (@@ -298,6 +302,7 @@ class DiscordProvider(OAuthProxy):fastmcp_access_token_expiry_seconds=fastmcp_access_token_expiry_seconds,token_expiry_threshold_seconds=token_expiry_threshold_seconds,enable_cimd=enable_cimd,+ identity_assertion=identity_assertion,)logger.debug(diff --git a/fastmcp_slim/fastmcp/server/auth/providers/github.py b/fastmcp_slim/fastmcp/server/auth/providers/github.pyindex 9353c1726..b958f274b 100644--- a/fastmcp_slim/fastmcp/server/auth/providers/github.py+++ b/fastmcp_slim/fastmcp/server/auth/providers/github.py@@ -30,6 +30,7 @@ from pydantic import AnyHttpUrlfrom fastmcp.server.auth import TokenVerifierfrom fastmcp.server.auth.auth import AccessToken+from fastmcp.server.auth.identity_assertion import IdentityAssertionfrom fastmcp.server.auth.oauth_proxy import OAuthProxyfrom fastmcp.utilities.auth import parse_scopesfrom fastmcp.utilities.logging import get_logger@@ -237,6 +238,7 @@ class GitHubProvider(OAuthProxy):token_expiry_threshold_seconds: int = 0,http_client: httpx2.AsyncClient | None = None,enable_cimd: bool = True,+ identity_assertion: IdentityAssertion | None = None,):"""Initialize GitHub OAuth provider.@@ -286,6 +288,8 @@ class GitHubProvider(OAuthProxy):refresh gracefully (e.g. `mcp-remote`). See `OAuthProxy` for details.token_expiry_threshold_seconds: Number of seconds before actual expiry totreat a token as expired, refreshing early to avoid races. Defaults to 0.+ identity_assertion: Optional SEP-990 ID-JAG configuration for+ identity-bound token exchange. Disabled by default."""# Parse scopes if provided as stringrequired_scopes_final = (@@ -322,6 +326,7 @@ class GitHubProvider(OAuthProxy):fastmcp_access_token_expiry_seconds=fastmcp_access_token_expiry_seconds,token_expiry_threshold_seconds=token_expiry_threshold_seconds,enable_cimd=enable_cimd,+ identity_assertion=identity_assertion,)logger.debug(diff --git a/fastmcp_slim/fastmcp/server/auth/providers/google.py b/fastmcp_slim/fastmcp/server/auth/providers/google.pyindex 4b5ea2037..1237258cc 100644--- a/fastmcp_slim/fastmcp/server/auth/providers/google.py+++ b/fastmcp_slim/fastmcp/server/auth/providers/google.py@@ -31,6 +31,7 @@ from pydantic import AnyHttpUrlfrom fastmcp.server.auth import TokenVerifierfrom fastmcp.server.auth.auth import AccessToken+from fastmcp.server.auth.identity_assertion import IdentityAssertionfrom fastmcp.server.auth.oauth_proxy import OAuthProxyfrom fastmcp.utilities.auth import parse_scopesfrom fastmcp.utilities.logging import get_logger@@ -298,6 +299,7 @@ class GoogleProvider(OAuthProxy):extra_authorize_params: dict[str, str] | None = None,http_client: httpx2.AsyncClient | None = None,enable_cimd: bool = True,+ identity_assertion: IdentityAssertion | None = None,):"""Initialize Google OAuth provider.@@ -362,6 +364,8 @@ class GoogleProvider(OAuthProxy):refresh gracefully (e.g. `mcp-remote`). See `OAuthProxy` for details.token_expiry_threshold_seconds: Number of seconds before actual expiry totreat a token as expired, refreshing early to avoid races. Defaults to 0.+ identity_assertion: Optional SEP-990 ID-JAG configuration for+ identity-bound token exchange. Disabled by default."""# Parse scopes if provided as string# Google requires at least one scope - openid is the minimal OIDC scope@@ -426,6 +430,7 @@ class GoogleProvider(OAuthProxy):extra_authorize_params=extra_authorize_params_final,valid_scopes=valid_scopes_final,enable_cimd=enable_cimd,+ identity_assertion=identity_assertion,)logger.debug(diff --git a/fastmcp_slim/fastmcp/server/auth/providers/huggingface.py b/fastmcp_slim/fastmcp/server/auth/providers/huggingface.pyindex 22b6c5d6b..4832ba2e1 100644--- a/fastmcp_slim/fastmcp/server/auth/providers/huggingface.py+++ b/fastmcp_slim/fastmcp/server/auth/providers/huggingface.py@@ -13,6 +13,7 @@ from pydantic import AnyHttpUrlfrom fastmcp.server.auth import TokenVerifierfrom fastmcp.server.auth.auth import AccessToken+from fastmcp.server.auth.identity_assertion import IdentityAssertionfrom fastmcp.server.auth.oauth_proxy import OAuthProxyfrom fastmcp.utilities.auth import parse_scopesfrom fastmcp.utilities.logging import get_logger@@ -200,6 +201,7 @@ class HuggingFaceProvider(OAuthProxy):extra_token_params: dict[str, str] | None = None,http_client: httpx2.AsyncClient | None = None,enable_cimd: bool = True,+ identity_assertion: IdentityAssertion | None = None,):"""Initialize Hugging Face OAuth provider.@@ -217,6 +219,8 @@ class HuggingFaceProvider(OAuthProxy):valid_scopes: Scopes clients may request. Defaults to required scopes.extra_authorize_params: Extra authorization parameters, such as``{"orgIds": "your-org-id"}`` for organization grants.+ identity_assertion: Optional SEP-990 ID-JAG configuration for+ identity-bound token exchange. Disabled by default."""required_scopes_final = (parse_scopes(required_scopes)@@ -263,6 +267,7 @@ class HuggingFaceProvider(OAuthProxy):else "none",valid_scopes=valid_scopes_final,enable_cimd=enable_cimd,+ identity_assertion=identity_assertion,)logger.debug(diff --git a/fastmcp_slim/fastmcp/server/auth/providers/oci.py b/fastmcp_slim/fastmcp/server/auth/providers/oci.pyindex 613efd69b..91f0d71e1 100644--- a/fastmcp_slim/fastmcp/server/auth/providers/oci.py+++ b/fastmcp_slim/fastmcp/server/auth/providers/oci.py@@ -82,6 +82,7 @@ from typing import Literalfrom key_value.aio.protocols import AsyncKeyValuefrom pydantic import AnyHttpUrl+from fastmcp.server.auth.identity_assertion import IdentityAssertionfrom fastmcp.server.auth.oidc_proxy import (DEFAULT_OIDC_DISCOVERY_TIMEOUT_SECONDS,OIDCProxy,@@ -142,6 +143,7 @@ class OCIProvider(OIDCProxy):fastmcp_access_token_expiry_seconds: int | None = None,token_expiry_threshold_seconds: int = 0,enable_cimd: bool = True,+ identity_assertion: IdentityAssertion | None = None,) -> None:"""Initialize OCI OIDC provider.@@ -177,6 +179,8 @@ class OCIProvider(OIDCProxy):treat a token as expired, refreshing early to avoid races. Defaults to 0.enable_cimd: Enable CIMD (Client ID Metadata Document) support for URL-basedclient IDs (default True). Set to False to disable.+ identity_assertion: Optional SEP-990 ID-JAG configuration for+ identity-bound token exchange. Disabled by default."""# Parse scopes if provided as stringoci_required_scopes = (@@ -204,6 +208,7 @@ class OCIProvider(OIDCProxy):fastmcp_access_token_expiry_seconds=fastmcp_access_token_expiry_seconds,token_expiry_threshold_seconds=token_expiry_threshold_seconds,enable_cimd=enable_cimd,+ identity_assertion=identity_assertion,)logger.debug(diff --git a/fastmcp_slim/fastmcp/server/auth/providers/workos.py b/fastmcp_slim/fastmcp/server/auth/providers/workos.pyindex 2e1e41433..9f9fef66b 100644--- a/fastmcp_slim/fastmcp/server/auth/providers/workos.py+++ b/fastmcp_slim/fastmcp/server/auth/providers/workos.py@@ -20,6 +20,7 @@ from starlette.responses import JSONResponsefrom starlette.routing import Routefrom fastmcp.server.auth import AccessToken, RemoteAuthProvider, TokenVerifier+from fastmcp.server.auth.identity_assertion import IdentityAssertionfrom fastmcp.server.auth.oauth_proxy import OAuthProxyfrom fastmcp.server.auth.providers.jwt import JWTVerifierfrom fastmcp.utilities.auth import parse_scopes@@ -187,6 +188,7 @@ class WorkOSProvider(OAuthProxy):extra_authorize_params: dict[str, str] | None = None,http_client: httpx2.AsyncClient | None = None,enable_cimd: bool = True,+ identity_assertion: IdentityAssertion | None = None,):"""Initialize WorkOS OAuth provider.@@ -241,6 +243,8 @@ class WorkOSProvider(OAuthProxy):is responsible for its lifecycle. When None (default), a fresh client is created per call.enable_cimd: Enable CIMD (Client ID Metadata Document) support for URL-basedclient IDs (default True). Set to False to disable.+ identity_assertion: Optional SEP-990 ID-JAG configuration for+ identity-bound token exchange. Disabled by default."""# Apply defaults and ensure authkit_domain is a full URLauthkit_domain_str = authkit_domain@@ -285,6 +289,7 @@ class WorkOSProvider(OAuthProxy):extra_authorize_params=extra_authorize_params,valid_scopes=valid_scopes_final,enable_cimd=enable_cimd,+ identity_assertion=identity_assertion,)logger.debug(diff --git a/tests/server/auth/providers/test_identity_assertion_forwarding.py b/tests/server/auth/providers/test_identity_assertion_forwarding.pynew file mode 100644index 000000000..b77e001a7--- /dev/null+++ b/tests/server/auth/providers/test_identity_assertion_forwarding.py@@ -0,0 +1,140 @@+"""OAuth provider constructors should expose the ID-JAG feature of their proxy base."""++import inspect++import pytest++from fastmcp.server.auth import IdentityAssertion+from fastmcp.server.auth.providers.auth0 import Auth0Provider+from fastmcp.server.auth.providers.aws import AWSCognitoProvider+from fastmcp.server.auth.providers.azure import AzureProvider+from fastmcp.server.auth.providers.clerk import ClerkProvider+from fastmcp.server.auth.providers.discord import DiscordProvider+from fastmcp.server.auth.providers.github import GitHubProvider+from fastmcp.server.auth.providers.google import GoogleProvider+from fastmcp.server.auth.providers.huggingface import HuggingFaceProvider+from fastmcp.server.auth.providers.oci import OCIProvider+from fastmcp.server.auth.providers.workos import WorkOSProvider+++ "provider",+ [+ Auth0Provider,+ AWSCognitoProvider,+ AzureProvider,+ ClerkProvider,+ DiscordProvider,+ GitHubProvider,+ GoogleProvider,+ HuggingFaceProvider,+ OCIProvider,+ WorkOSProvider,+ ],+)+def test_identity_assertion_is_public_provider_parameter(provider: type) -> None:+ signature = inspect.signature(provider)+ assert "identity_assertion" in signature.parameters+ assert signature.parameters["identity_assertion"].default is None+++ ("provider", "kwargs"),+ [+ (GoogleProvider, {"client_id": "test", "client_secret": "secret"}),+ (GitHubProvider, {"client_id": "test", "client_secret": "secret"}),+ (DiscordProvider, {"client_id": "test", "client_secret": "secret"}),+ (HuggingFaceProvider, {"client_id": "test", "client_secret": "secret"}),+ (+ ClerkProvider,+ {+ "domain": "clerk.example.test",+ "client_id": "test",+ "client_secret": "secret",+ },+ ),+ (+ WorkOSProvider,+ {+ "client_id": "test",+ "client_secret": "secret",+ "authkit_domain": "https://authkit.example.test",+ },+ ),+ (+ AzureProvider,+ {+ "client_id": "test",+ "client_secret": "secret",+ "tenant_id": "test-tenant",+ "required_scopes": ["read"],+ },+ ),+ ],+)+def test_provider_forwards_identity_assertion(provider: type, kwargs: dict) -> None:+ assertion = IdentityAssertion(trusted_issuers=["https://issuer.example.test"])+ instance = provider(+ **kwargs,+ base_url="https://resource.example.test",+ identity_assertion=assertion,+ )+ assert instance._identity_assertion is assertion+ assert instance._identity_assertion_validator is not None+++def test_provider_remains_disabled_by_default() -> None:+ instance = GoogleProvider(+ client_id="test",+ client_secret="secret",+ base_url="https://resource.example.test",+ )+ assert instance._identity_assertion is None+ assert instance._identity_assertion_validator is None+++ ("provider", "kwargs"),+ [+ (+ Auth0Provider,+ {+ "config_url": "https://auth.example.test/.well-known/openid-configuration",+ "client_id": "test",+ "client_secret": "secret",+ "audience": "test-audience",+ },+ ),+ (+ AWSCognitoProvider,+ {+ "user_pool_id": "us-east-1_test",+ "client_id": "test",+ "client_secret": "secret",+ },+ ),+ (+ OCIProvider,+ {+ "config_url": "https://auth.example.test/.well-known/openid-configuration",+ "client_id": "test",+ "client_secret": "secret",+ },+ ),+ ],+)+def test_oidc_provider_forwards_identity_assertion(+ provider: type, kwargs: dict+) -> None:+ from unittest.mock import patch++ from fastmcp.server.auth.oidc_proxy import OIDCProxy++ assertion = IdentityAssertion(trusted_issuers=["https://issuer.example.test"])+ with patch.object(OIDCProxy, "__init__", return_value=None) as base_init:+ provider(+ **kwargs,+ base_url="https://resource.example.test",+ identity_assertion=assertion,+ )+ assert base_init.call_args.kwargs["identity_assertion"] is assertion