π The fast, Pythonic way to build MCP servers and clients.
Add forward_resource flag to OAuthProxy (#3711)
Jeremiah Lowin665514e19a78
diff --git a/src/fastmcp/server/auth/oauth_proxy/consent.py b/src/fastmcp/server/auth/oauth_proxy/consent.pyindex b2ad20642..03b1e6ef3 100644--- a/src/fastmcp/server/auth/oauth_proxy/consent.py+++ b/src/fastmcp/server/auth/oauth_proxy/consent.py@@ -285,8 +285,9 @@ class ConsentMixin:query_params["code_challenge_method"] = "S256"# Forward resource indicator if present in transaction- if resource := transaction.get("resource"):- query_params["resource"] = resource+ if self._forward_resource:+ if resource := transaction.get("resource"):+ query_params["resource"] = resource# Extra configured parametersif self._extra_authorize_params:diff --git a/src/fastmcp/server/auth/oauth_proxy/proxy.py b/src/fastmcp/server/auth/oauth_proxy/proxy.pyindex b41c9d318..bcad01941 100644--- a/src/fastmcp/server/auth/oauth_proxy/proxy.py+++ b/src/fastmcp/server/auth/oauth_proxy/proxy.py@@ -248,6 +248,8 @@ class OAuthProxy(OAuthProvider, ConsentMixin):valid_scopes: list[str] | None = None,# PKCE configurationforward_pkce: bool = True,+ # Resource indicator (RFC 8707)+ forward_resource: bool = True,# Token endpoint authenticationtoken_endpoint_auth_method: str | None = None,# Extra parameters to forward to authorization endpoint@@ -382,6 +384,8 @@ class OAuthProxy(OAuthProvider, ConsentMixin):# PKCE configurationself._forward_pkce: bool = forward_pkce+ # Resource indicator (RFC 8707)+ self._forward_resource: bool = forward_resource# Token endpoint authenticationself._token_endpoint_auth_method: str | None = token_endpoint_auth_methoddiff --git a/src/fastmcp/server/auth/oidc_proxy.py b/src/fastmcp/server/auth/oidc_proxy.pyindex 2da50bbde..ebf048c5a 100644--- a/src/fastmcp/server/auth/oidc_proxy.py+++ b/src/fastmcp/server/auth/oidc_proxy.py@@ -226,6 +226,7 @@ class OIDCProxy(OAuthProxy):# Consent screen configurationrequire_authorization_consent: bool | Literal["external"] = True,consent_csp_policy: str | None = None,+ forward_resource: bool = True,# Extra parametersextra_authorize_params: dict[str, str] | None = None,extra_token_params: dict[str, str] | None = None,@@ -377,6 +378,7 @@ class OIDCProxy(OAuthProxy):"token_endpoint_auth_method": token_endpoint_auth_method,"require_authorization_consent": require_authorization_consent,"consent_csp_policy": consent_csp_policy,+ "forward_resource": forward_resource,"fallback_access_token_expiry_seconds": fallback_access_token_expiry_seconds,"enable_cimd": enable_cimd,}diff --git a/src/fastmcp/server/auth/providers/auth0.py b/src/fastmcp/server/auth/providers/auth0.pyindex d38e4046d..5b1017c6a 100644--- a/src/fastmcp/server/auth/providers/auth0.py+++ b/src/fastmcp/server/auth/providers/auth0.py@@ -73,6 +73,7 @@ class Auth0Provider(OIDCProxy):jwt_signing_key: str | bytes | None = None,require_authorization_consent: bool | Literal["external"] = True,consent_csp_policy: str | None = None,+ forward_resource: bool = True,) -> None:"""Initialize Auth0 OAuth provider.@@ -120,6 +121,7 @@ class Auth0Provider(OIDCProxy):jwt_signing_key=jwt_signing_key,require_authorization_consent=require_authorization_consent,consent_csp_policy=consent_csp_policy,+ forward_resource=forward_resource,)logger.debug(diff --git a/src/fastmcp/server/auth/providers/aws.py b/src/fastmcp/server/auth/providers/aws.pyindex dbec10e2d..fc5ca0666 100644--- a/src/fastmcp/server/auth/providers/aws.py+++ b/src/fastmcp/server/auth/providers/aws.py@@ -111,6 +111,7 @@ class AWSCognitoProvider(OIDCProxy):jwt_signing_key: str | bytes | None = None,require_authorization_consent: bool | Literal["external"] = True,consent_csp_policy: str | None = None,+ forward_resource: bool = True,):"""Initialize AWS Cognito OAuth provider.@@ -167,6 +168,7 @@ class AWSCognitoProvider(OIDCProxy):jwt_signing_key=jwt_signing_key,require_authorization_consent=require_authorization_consent,consent_csp_policy=consent_csp_policy,+ forward_resource=forward_resource,)logger.debug(diff --git a/src/fastmcp/server/auth/providers/azure.py b/src/fastmcp/server/auth/providers/azure.pyindex 00c1ab154..cd1de2c4a 100644--- a/src/fastmcp/server/auth/providers/azure.py+++ b/src/fastmcp/server/auth/providers/azure.py@@ -112,6 +112,7 @@ class AzureProvider(OAuthProxy):jwt_signing_key: str | bytes | None = None,require_authorization_consent: bool | Literal["external"] = True,consent_csp_policy: str | None = None,+ forward_resource: bool = True,base_authority: str = "login.microsoftonline.com",http_client: httpx.AsyncClient | None = None,enable_cimd: bool = True,@@ -248,6 +249,7 @@ class AzureProvider(OAuthProxy):jwt_signing_key=jwt_signing_key,require_authorization_consent=require_authorization_consent,consent_csp_policy=consent_csp_policy,+ forward_resource=forward_resource,valid_scopes=parsed_required_scopes,enable_cimd=enable_cimd,)diff --git a/src/fastmcp/server/auth/providers/clerk.py b/src/fastmcp/server/auth/providers/clerk.pyindex 3faa97220..409a065b3 100644--- a/src/fastmcp/server/auth/providers/clerk.py+++ b/src/fastmcp/server/auth/providers/clerk.py@@ -287,6 +287,7 @@ class ClerkProvider(OAuthProxy):jwt_signing_key: str | bytes | None = None,require_authorization_consent: bool | Literal["external"] = True,consent_csp_policy: str | None = None,+ forward_resource: bool = True,extra_authorize_params: dict[str, str] | None = None,http_client: httpx.AsyncClient | None = None,enable_cimd: bool = True,@@ -370,6 +371,7 @@ class ClerkProvider(OAuthProxy):jwt_signing_key=jwt_signing_key,require_authorization_consent=require_authorization_consent,consent_csp_policy=consent_csp_policy,+ forward_resource=forward_resource,extra_authorize_params=extra_authorize_params_final or None,valid_scopes=parsed_valid_scopes,enable_cimd=enable_cimd,diff --git a/src/fastmcp/server/auth/providers/discord.py b/src/fastmcp/server/auth/providers/discord.pyindex 15bf9e5dc..d646743f9 100644--- a/src/fastmcp/server/auth/providers/discord.py+++ b/src/fastmcp/server/auth/providers/discord.py@@ -205,6 +205,7 @@ class DiscordProvider(OAuthProxy):jwt_signing_key: str | bytes | None = None,require_authorization_consent: bool | Literal["external"] = True,consent_csp_policy: str | None = None,+ forward_resource: bool = True,http_client: httpx.AsyncClient | None = None,enable_cimd: bool = True,):@@ -272,6 +273,7 @@ class DiscordProvider(OAuthProxy):jwt_signing_key=jwt_signing_key,require_authorization_consent=require_authorization_consent,consent_csp_policy=consent_csp_policy,+ forward_resource=forward_resource,enable_cimd=enable_cimd,)diff --git a/src/fastmcp/server/auth/providers/github.py b/src/fastmcp/server/auth/providers/github.pyindex e0d140d38..b8f5a16e2 100644--- a/src/fastmcp/server/auth/providers/github.py+++ b/src/fastmcp/server/auth/providers/github.py@@ -220,6 +220,7 @@ class GitHubProvider(OAuthProxy):jwt_signing_key: str | bytes | None = None,require_authorization_consent: bool | Literal["external"] = True,consent_csp_policy: str | None = None,+ forward_resource: bool = True,http_client: httpx.AsyncClient | None = None,enable_cimd: bool = True,):@@ -287,6 +288,7 @@ class GitHubProvider(OAuthProxy):jwt_signing_key=jwt_signing_key,require_authorization_consent=require_authorization_consent,consent_csp_policy=consent_csp_policy,+ forward_resource=forward_resource,enable_cimd=enable_cimd,)diff --git a/src/fastmcp/server/auth/providers/google.py b/src/fastmcp/server/auth/providers/google.pyindex 8557248a9..48b84b9c0 100644--- a/src/fastmcp/server/auth/providers/google.py+++ b/src/fastmcp/server/auth/providers/google.py@@ -245,6 +245,7 @@ class GoogleProvider(OAuthProxy):jwt_signing_key: str | bytes | None = None,require_authorization_consent: bool | Literal["external"] = True,consent_csp_policy: str | None = None,+ forward_resource: bool = True,extra_authorize_params: dict[str, str] | None = None,http_client: httpx.AsyncClient | None = None,enable_cimd: bool = True,@@ -347,6 +348,7 @@ class GoogleProvider(OAuthProxy):jwt_signing_key=jwt_signing_key,require_authorization_consent=require_authorization_consent,consent_csp_policy=consent_csp_policy,+ forward_resource=forward_resource,extra_authorize_params=extra_authorize_params_final,valid_scopes=valid_scopes_final,enable_cimd=enable_cimd,diff --git a/src/fastmcp/server/auth/providers/oci.py b/src/fastmcp/server/auth/providers/oci.pyindex d4bf0d0c8..98011e4ed 100644--- a/src/fastmcp/server/auth/providers/oci.py+++ b/src/fastmcp/server/auth/providers/oci.py@@ -132,6 +132,7 @@ class OCIProvider(OIDCProxy):jwt_signing_key: str | bytes | None = None,require_authorization_consent: bool | Literal["external"] = True,consent_csp_policy: str | None = None,+ forward_resource: bool = True,) -> None:"""Initialize OCI OIDC provider.@@ -165,6 +166,7 @@ class OCIProvider(OIDCProxy):jwt_signing_key=jwt_signing_key,require_authorization_consent=require_authorization_consent,consent_csp_policy=consent_csp_policy,+ forward_resource=forward_resource,)logger.debug(diff --git a/src/fastmcp/server/auth/providers/workos.py b/src/fastmcp/server/auth/providers/workos.pyindex 957e29b0e..85dd8feca 100644--- a/src/fastmcp/server/auth/providers/workos.py+++ b/src/fastmcp/server/auth/providers/workos.py@@ -173,6 +173,7 @@ class WorkOSProvider(OAuthProxy):jwt_signing_key: str | bytes | None = None,require_authorization_consent: bool | Literal["external"] = True,consent_csp_policy: str | None = None,+ forward_resource: bool = True,http_client: httpx.AsyncClient | None = None,enable_cimd: bool = True,):@@ -240,6 +241,7 @@ class WorkOSProvider(OAuthProxy):jwt_signing_key=jwt_signing_key,require_authorization_consent=require_authorization_consent,consent_csp_policy=consent_csp_policy,+ forward_resource=forward_resource,enable_cimd=enable_cimd,)