Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

feat: type require_authorization_consent as bool | Literal["external"] (#3473)

Matthieu B72350294865d
diff --git a/src/fastmcp/server/auth/oauth_proxy/proxy.py b/src/fastmcp/server/auth/oauth_proxy/proxy.py
index 281d194ce..470ffd0c5 100644
--- a/src/fastmcp/server/auth/oauth_proxy/proxy.py
+++ b/src/fastmcp/server/auth/oauth_proxy/proxy.py
@@ -22,7 +22,7 @@ import hashlib
import secrets
import time
from base64 import urlsafe_b64encode
-from typing import Any
+from typing import Any, Literal
from urllib.parse import urlencode, urlparse, urlunparse
import httpx
@@ -257,7 +257,7 @@ class OAuthProxy(OAuthProvider, ConsentMixin):
# JWT signing key
jwt_signing_key: str | bytes | None = None,
# Consent screen configuration
- require_authorization_consent: bool = True,
+ require_authorization_consent: bool | Literal["external"] = True,
consent_csp_policy: str | None = None,
# Token expiry fallback
fallback_access_token_expiry_seconds: int | None = None,
@@ -305,7 +305,9 @@ class OAuthProxy(OAuthProvider, ConsentMixin):
require_authorization_consent: Whether to require user consent before authorizing clients (default True).
When True, users see a consent screen before being redirected to the upstream IdP.
When False, authorization proceeds directly without user confirmation.
- SECURITY WARNING: Only disable for local development or testing environments.
+ When "external", the built-in consent screen is skipped but no warning is
+ logged, indicating that consent is handled externally (e.g. by the upstream IdP).
+ SECURITY WARNING: Only set to False for local development or testing environments.
consent_csp_policy: Content Security Policy for the consent page.
If None (default), uses the built-in CSP policy with appropriate directives.
If empty string "", disables CSP entirely (no meta tag is rendered).
@@ -379,9 +381,15 @@ class OAuthProxy(OAuthProvider, ConsentMixin):
self._token_endpoint_auth_method: str | None = token_endpoint_auth_method
# Consent screen configuration
- self._require_authorization_consent: bool = require_authorization_consent
+ self._require_authorization_consent: bool | Literal["external"] = (
+ require_authorization_consent
+ )
self._consent_csp_policy: str | None = consent_csp_policy
- if not require_authorization_consent:
+ if require_authorization_consent == "external":
+ logger.info(
+ "Built-in consent screen disabled; consent is handled externally."
+ )
+ elif not require_authorization_consent:
logger.warning(
"Authorization consent screen disabled - only use for local development or testing. "
+ "In production, this screen protects against confused deputy attacks."
@@ -786,8 +794,8 @@ class OAuthProxy(OAuthProvider, ConsentMixin):
ttl=15 * 60, # Auto-expire after 15 minutes
)
- # If consent is disabled, skip consent screen and go directly to upstream IdP
- if not self._require_authorization_consent:
+ # If consent is disabled or handled externally, skip consent screen
+ if self._require_authorization_consent is not True:
upstream_url = self._build_upstream_authorize_url(
txn_id, transaction.model_dump()
)
@@ -1693,7 +1701,7 @@ class OAuthProxy(OAuthProvider, ConsentMixin):
# When consent is enabled, the browser that approved consent receives
# a signed cookie. A different browser (e.g., a victim lured to the
# IdP URL) won't have this cookie and will be rejected.
- if self._require_authorization_consent:
+ if self._require_authorization_consent is True:
consent_token = transaction_model.consent_token
if not consent_token:
logger.error("Transaction %s missing consent_token", txn_id)
diff --git a/src/fastmcp/server/auth/oidc_proxy.py b/src/fastmcp/server/auth/oidc_proxy.py
index 7081e05be..b543b9f4e 100644
--- a/src/fastmcp/server/auth/oidc_proxy.py
+++ b/src/fastmcp/server/auth/oidc_proxy.py
@@ -10,6 +10,7 @@ This implementation is based on:
"""
from collections.abc import Sequence
+from typing import Literal
import httpx
from key_value.aio.protocols import AsyncKeyValue
@@ -223,7 +224,7 @@ class OIDCProxy(OAuthProxy):
# Token validation configuration
token_endpoint_auth_method: str | None = None,
# Consent screen configuration
- require_authorization_consent: bool = True,
+ require_authorization_consent: bool | Literal["external"] = True,
consent_csp_policy: str | None = None,
# Extra parameters
extra_authorize_params: dict[str, str] | None = None,
@@ -271,7 +272,9 @@ class OIDCProxy(OAuthProxy):
require_authorization_consent: Whether to require user consent before authorizing clients (default True).
When True, users see a consent screen before being redirected to the upstream IdP.
When False, authorization proceeds directly without user confirmation.
- SECURITY WARNING: Only disable for local development or testing environments.
+ When "external", the built-in consent screen is skipped but no warning is
+ logged, indicating that consent is handled externally (e.g. by the upstream IdP).
+ SECURITY WARNING: Only set to False for local development or testing environments.
consent_csp_policy: Content Security Policy for the consent page.
If None (default), uses the built-in CSP policy with appropriate directives.
If empty string "", disables CSP entirely (no meta tag is rendered).
diff --git a/src/fastmcp/server/auth/providers/auth0.py b/src/fastmcp/server/auth/providers/auth0.py
index 3eec61776..d38e4046d 100644
--- a/src/fastmcp/server/auth/providers/auth0.py
+++ b/src/fastmcp/server/auth/providers/auth0.py
@@ -21,6 +21,8 @@ Example:
```
"""
+from typing import Literal
+
from key_value.aio.protocols import AsyncKeyValue
from pydantic import AnyHttpUrl
@@ -69,7 +71,7 @@ class Auth0Provider(OIDCProxy):
allowed_client_redirect_uris: list[str] | None = None,
client_storage: AsyncKeyValue | None = None,
jwt_signing_key: str | bytes | None = None,
- require_authorization_consent: bool = True,
+ require_authorization_consent: bool | Literal["external"] = True,
consent_csp_policy: str | None = None,
) -> None:
"""Initialize Auth0 OAuth provider.
@@ -95,7 +97,9 @@ class Auth0Provider(OIDCProxy):
require_authorization_consent: Whether to require user consent before authorizing clients (default True).
When True, users see a consent screen before being redirected to Auth0.
When False, authorization proceeds directly without user confirmation.
- SECURITY WARNING: Only disable for local development or testing environments.
+ When "external", the built-in consent screen is skipped but no warning is
+ logged, indicating that consent is handled externally (e.g. by the upstream IdP).
+ SECURITY WARNING: Only set to False for local development or testing environments.
"""
# Parse scopes if provided as string
auth0_required_scopes = (
diff --git a/src/fastmcp/server/auth/providers/aws.py b/src/fastmcp/server/auth/providers/aws.py
index 58f1ab5a1..dbec10e2d 100644
--- a/src/fastmcp/server/auth/providers/aws.py
+++ b/src/fastmcp/server/auth/providers/aws.py
@@ -23,6 +23,8 @@ Example:
from __future__ import annotations
+from typing import Literal
+
from key_value.aio.protocols import AsyncKeyValue
from pydantic import AnyHttpUrl
@@ -107,7 +109,7 @@ class AWSCognitoProvider(OIDCProxy):
allowed_client_redirect_uris: list[str] | None = None,
client_storage: AsyncKeyValue | None = None,
jwt_signing_key: str | bytes | None = None,
- require_authorization_consent: bool = True,
+ require_authorization_consent: bool | Literal["external"] = True,
consent_csp_policy: str | None = None,
):
"""Initialize AWS Cognito OAuth provider.
@@ -133,7 +135,9 @@ class AWSCognitoProvider(OIDCProxy):
require_authorization_consent: Whether to require user consent before authorizing clients (default True).
When True, users see a consent screen before being redirected to AWS Cognito.
When False, authorization proceeds directly without user confirmation.
- SECURITY WARNING: Only disable for local development or testing environments.
+ When "external", the built-in consent screen is skipped but no warning is
+ logged, indicating that consent is handled externally (e.g. by the upstream IdP).
+ SECURITY WARNING: Only set to False for local development or testing environments.
"""
# Parse scopes if provided as string
required_scopes_final = (
diff --git a/src/fastmcp/server/auth/providers/azure.py b/src/fastmcp/server/auth/providers/azure.py
index 009cf9316..2820fd513 100644
--- a/src/fastmcp/server/auth/providers/azure.py
+++ b/src/fastmcp/server/auth/providers/azure.py
@@ -8,7 +8,7 @@ from __future__ import annotations
import hashlib
from collections import OrderedDict
-from typing import TYPE_CHECKING, Any, cast
+from typing import TYPE_CHECKING, Any, Literal, cast
import httpx
from key_value.aio.protocols import AsyncKeyValue
@@ -107,7 +107,7 @@ class AzureProvider(OAuthProxy):
allowed_client_redirect_uris: list[str] | None = None,
client_storage: AsyncKeyValue | None = None,
jwt_signing_key: str | bytes | None = None,
- require_authorization_consent: bool = True,
+ require_authorization_consent: bool | Literal["external"] = True,
consent_csp_policy: str | None = None,
base_authority: str = "login.microsoftonline.com",
http_client: httpx.AsyncClient | None = None,
@@ -154,7 +154,9 @@ class AzureProvider(OAuthProxy):
require_authorization_consent: Whether to require user consent before authorizing clients (default True).
When True, users see a consent screen before being redirected to Azure.
When False, authorization proceeds directly without user confirmation.
- SECURITY WARNING: Only disable for local development or testing environments.
+ When "external", the built-in consent screen is skipped but no warning is
+ logged, indicating that consent is handled externally (e.g. by the upstream IdP).
+ SECURITY WARNING: Only set to False for local development or testing environments.
http_client: Optional httpx.AsyncClient for connection pooling in JWKS fetches.
When provided, the client is reused for JWT key fetches and the caller
is responsible for its lifecycle. When None (default), a fresh client is created per fetch.
diff --git a/src/fastmcp/server/auth/providers/discord.py b/src/fastmcp/server/auth/providers/discord.py
index c07dfd86f..953ccef6c 100644
--- a/src/fastmcp/server/auth/providers/discord.py
+++ b/src/fastmcp/server/auth/providers/discord.py
@@ -24,6 +24,7 @@ from __future__ import annotations
import contextlib
import time
from datetime import datetime
+from typing import Literal
import httpx
from key_value.aio.protocols import AsyncKeyValue
@@ -202,7 +203,7 @@ class DiscordProvider(OAuthProxy):
allowed_client_redirect_uris: list[str] | None = None,
client_storage: AsyncKeyValue | None = None,
jwt_signing_key: str | bytes | None = None,
- require_authorization_consent: bool = True,
+ require_authorization_consent: bool | Literal["external"] = True,
consent_csp_policy: str | None = None,
http_client: httpx.AsyncClient | None = None,
):
@@ -231,7 +232,9 @@ class DiscordProvider(OAuthProxy):
require_authorization_consent: Whether to require user consent before authorizing clients (default True).
When True, users see a consent screen before being redirected to Discord.
When False, authorization proceeds directly without user confirmation.
- SECURITY WARNING: Only disable for local development or testing environments.
+ When "external", the built-in consent screen is skipped but no warning is
+ logged, indicating that consent is handled externally (e.g. by the upstream IdP).
+ SECURITY WARNING: Only set to False for local development or testing environments.
http_client: Optional httpx.AsyncClient for connection pooling in token verification.
When provided, the client is reused across verify_token calls and the caller
is responsible for its lifecycle. When None (default), a fresh client is created per call.
diff --git a/src/fastmcp/server/auth/providers/github.py b/src/fastmcp/server/auth/providers/github.py
index 3d0c31d27..303d97ddd 100644
--- a/src/fastmcp/server/auth/providers/github.py
+++ b/src/fastmcp/server/auth/providers/github.py
@@ -22,6 +22,7 @@ Example:
from __future__ import annotations
import contextlib
+from typing import Literal
import httpx
from key_value.aio.protocols import AsyncKeyValue
@@ -191,7 +192,7 @@ class GitHubProvider(OAuthProxy):
allowed_client_redirect_uris: list[str] | None = None,
client_storage: AsyncKeyValue | None = None,
jwt_signing_key: str | bytes | None = None,
- require_authorization_consent: bool = True,
+ require_authorization_consent: bool | Literal["external"] = True,
consent_csp_policy: str | None = None,
http_client: httpx.AsyncClient | None = None,
):
@@ -217,7 +218,9 @@ class GitHubProvider(OAuthProxy):
require_authorization_consent: Whether to require user consent before authorizing clients (default True).
When True, users see a consent screen before being redirected to GitHub.
When False, authorization proceeds directly without user confirmation.
- SECURITY WARNING: Only disable for local development or testing environments.
+ When "external", the built-in consent screen is skipped but no warning is
+ logged, indicating that consent is handled externally (e.g. by the upstream IdP).
+ SECURITY WARNING: Only set to False for local development or testing environments.
http_client: Optional httpx.AsyncClient for connection pooling in token verification.
When provided, the client is reused across verify_token calls and the caller
is responsible for its lifecycle. When None (default), a fresh client is created per call.
diff --git a/src/fastmcp/server/auth/providers/google.py b/src/fastmcp/server/auth/providers/google.py
index 4673252b8..f35bf1bfa 100644
--- a/src/fastmcp/server/auth/providers/google.py
+++ b/src/fastmcp/server/auth/providers/google.py
@@ -23,6 +23,7 @@ from __future__ import annotations
import contextlib
import time
+from typing import Literal
import httpx
from key_value.aio.protocols import AsyncKeyValue
@@ -228,7 +229,7 @@ class GoogleProvider(OAuthProxy):
allowed_client_redirect_uris: list[str] | None = None,
client_storage: AsyncKeyValue | None = None,
jwt_signing_key: str | bytes | None = None,
- require_authorization_consent: bool = True,
+ require_authorization_consent: bool | Literal["external"] = True,
consent_csp_policy: str | None = None,
extra_authorize_params: dict[str, str] | None = None,
http_client: httpx.AsyncClient | None = None,
@@ -264,7 +265,9 @@ class GoogleProvider(OAuthProxy):
require_authorization_consent: Whether to require user consent before authorizing clients (default True).
When True, users see a consent screen before being redirected to Google.
When False, authorization proceeds directly without user confirmation.
- SECURITY WARNING: Only disable for local development or testing environments.
+ When "external", the built-in consent screen is skipped but no warning is
+ logged, indicating that consent is handled externally (e.g. by Google's own consent).
+ SECURITY WARNING: Only set to False for local development or testing environments.
extra_authorize_params: Additional parameters to forward to Google's authorization endpoint.
By default, GoogleProvider sets {"access_type": "offline", "prompt": "consent"} to ensure
refresh tokens are returned. You can override these defaults or add additional parameters.
diff --git a/src/fastmcp/server/auth/providers/oci.py b/src/fastmcp/server/auth/providers/oci.py
index 29527f07a..d4bf0d0c8 100644
--- a/src/fastmcp/server/auth/providers/oci.py
+++ b/src/fastmcp/server/auth/providers/oci.py
@@ -77,6 +77,8 @@ Example:
```
"""
+from typing import Literal
+
from key_value.aio.protocols import AsyncKeyValue
from pydantic import AnyHttpUrl
@@ -128,7 +130,7 @@ class OCIProvider(OIDCProxy):
allowed_client_redirect_uris: list[str] | None = None,
client_storage: AsyncKeyValue | None = None,
jwt_signing_key: str | bytes | None = None,
- require_authorization_consent: bool = True,
+ require_authorization_consent: bool | Literal["external"] = True,
consent_csp_policy: str | None = None,
) -> None:
"""Initialize OCI OIDC provider.
diff --git a/src/fastmcp/server/auth/providers/workos.py b/src/fastmcp/server/auth/providers/workos.py
index 204beeb48..7868bb04d 100644
--- a/src/fastmcp/server/auth/providers/workos.py
+++ b/src/fastmcp/server/auth/providers/workos.py
@@ -11,6 +11,7 @@ Choose based on your WorkOS setup and authentication requirements.
from __future__ import annotations
import contextlib
+from typing import Literal
import httpx
from key_value.aio.protocols import AsyncKeyValue
@@ -170,7 +171,7 @@ class WorkOSProvider(OAuthProxy):
allowed_client_redirect_uris: list[str] | None = None,
client_storage: AsyncKeyValue | None = None,
jwt_signing_key: str | bytes | None = None,
- require_authorization_consent: bool = True,
+ require_authorization_consent: bool | Literal["external"] = True,
consent_csp_policy: str | None = None,
http_client: httpx.AsyncClient | None = None,
):
@@ -197,7 +198,9 @@ class WorkOSProvider(OAuthProxy):
require_authorization_consent: Whether to require user consent before authorizing clients (default True).
When True, users see a consent screen before being redirected to WorkOS.
When False, authorization proceeds directly without user confirmation.
- SECURITY WARNING: Only disable for local development or testing environments.
+ When "external", the built-in consent screen is skipped but no warning is
+ logged, indicating that consent is handled externally (e.g. by the upstream IdP).
+ SECURITY WARNING: Only set to False for local development or testing environments.
http_client: Optional httpx.AsyncClient for connection pooling in token verification.
When provided, the client is reused across verify_token calls and the caller
is responsible for its lifecycle. When None (default), a fresh client is created per call.