Skip to content

Commit 665514e

Browse files
authored
Add forward_resource flag to OAuthProxy (#3711)
1 parent f189d1f commit 665514e

12 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/fastmcp/server/auth/oauth_proxy/consent.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,9 @@ def _build_upstream_authorize_url(
285285
query_params["code_challenge_method"] = "S256"
286286

287287
# Forward resource indicator if present in transaction
288-
if resource := transaction.get("resource"):
289-
query_params["resource"] = resource
288+
if self._forward_resource:
289+
if resource := transaction.get("resource"):
290+
query_params["resource"] = resource
290291

291292
# Extra configured parameters
292293
if self._extra_authorize_params:

src/fastmcp/server/auth/oauth_proxy/proxy.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ def __init__(
248248
valid_scopes: list[str] | None = None,
249249
# PKCE configuration
250250
forward_pkce: bool = True,
251+
# Resource indicator (RFC 8707)
252+
forward_resource: bool = True,
251253
# Token endpoint authentication
252254
token_endpoint_auth_method: str | None = None,
253255
# Extra parameters to forward to authorization endpoint
@@ -382,6 +384,8 @@ def __init__(
382384

383385
# PKCE configuration
384386
self._forward_pkce: bool = forward_pkce
387+
# Resource indicator (RFC 8707)
388+
self._forward_resource: bool = forward_resource
385389

386390
# Token endpoint authentication
387391
self._token_endpoint_auth_method: str | None = token_endpoint_auth_method

src/fastmcp/server/auth/oidc_proxy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ def __init__(
226226
# Consent screen configuration
227227
require_authorization_consent: bool | Literal["external"] = True,
228228
consent_csp_policy: str | None = None,
229+
forward_resource: bool = True,
229230
# Extra parameters
230231
extra_authorize_params: dict[str, str] | None = None,
231232
extra_token_params: dict[str, str] | None = None,
@@ -377,6 +378,7 @@ def __init__(
377378
"token_endpoint_auth_method": token_endpoint_auth_method,
378379
"require_authorization_consent": require_authorization_consent,
379380
"consent_csp_policy": consent_csp_policy,
381+
"forward_resource": forward_resource,
380382
"fallback_access_token_expiry_seconds": fallback_access_token_expiry_seconds,
381383
"enable_cimd": enable_cimd,
382384
}

src/fastmcp/server/auth/providers/auth0.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def __init__(
7373
jwt_signing_key: str | bytes | None = None,
7474
require_authorization_consent: bool | Literal["external"] = True,
7575
consent_csp_policy: str | None = None,
76+
forward_resource: bool = True,
7677
) -> None:
7778
"""Initialize Auth0 OAuth provider.
7879
@@ -120,6 +121,7 @@ def __init__(
120121
jwt_signing_key=jwt_signing_key,
121122
require_authorization_consent=require_authorization_consent,
122123
consent_csp_policy=consent_csp_policy,
124+
forward_resource=forward_resource,
123125
)
124126

125127
logger.debug(

src/fastmcp/server/auth/providers/aws.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def __init__(
111111
jwt_signing_key: str | bytes | None = None,
112112
require_authorization_consent: bool | Literal["external"] = True,
113113
consent_csp_policy: str | None = None,
114+
forward_resource: bool = True,
114115
):
115116
"""Initialize AWS Cognito OAuth provider.
116117
@@ -167,6 +168,7 @@ def __init__(
167168
jwt_signing_key=jwt_signing_key,
168169
require_authorization_consent=require_authorization_consent,
169170
consent_csp_policy=consent_csp_policy,
171+
forward_resource=forward_resource,
170172
)
171173

172174
logger.debug(

src/fastmcp/server/auth/providers/azure.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def __init__(
112112
jwt_signing_key: str | bytes | None = None,
113113
require_authorization_consent: bool | Literal["external"] = True,
114114
consent_csp_policy: str | None = None,
115+
forward_resource: bool = True,
115116
base_authority: str = "login.microsoftonline.com",
116117
http_client: httpx.AsyncClient | None = None,
117118
enable_cimd: bool = True,
@@ -248,6 +249,7 @@ def __init__(
248249
jwt_signing_key=jwt_signing_key,
249250
require_authorization_consent=require_authorization_consent,
250251
consent_csp_policy=consent_csp_policy,
252+
forward_resource=forward_resource,
251253
valid_scopes=parsed_required_scopes,
252254
enable_cimd=enable_cimd,
253255
)

src/fastmcp/server/auth/providers/clerk.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ def __init__(
287287
jwt_signing_key: str | bytes | None = None,
288288
require_authorization_consent: bool | Literal["external"] = True,
289289
consent_csp_policy: str | None = None,
290+
forward_resource: bool = True,
290291
extra_authorize_params: dict[str, str] | None = None,
291292
http_client: httpx.AsyncClient | None = None,
292293
enable_cimd: bool = True,
@@ -370,6 +371,7 @@ def __init__(
370371
jwt_signing_key=jwt_signing_key,
371372
require_authorization_consent=require_authorization_consent,
372373
consent_csp_policy=consent_csp_policy,
374+
forward_resource=forward_resource,
373375
extra_authorize_params=extra_authorize_params_final or None,
374376
valid_scopes=parsed_valid_scopes,
375377
enable_cimd=enable_cimd,

src/fastmcp/server/auth/providers/discord.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ def __init__(
205205
jwt_signing_key: str | bytes | None = None,
206206
require_authorization_consent: bool | Literal["external"] = True,
207207
consent_csp_policy: str | None = None,
208+
forward_resource: bool = True,
208209
http_client: httpx.AsyncClient | None = None,
209210
enable_cimd: bool = True,
210211
):
@@ -272,6 +273,7 @@ def __init__(
272273
jwt_signing_key=jwt_signing_key,
273274
require_authorization_consent=require_authorization_consent,
274275
consent_csp_policy=consent_csp_policy,
276+
forward_resource=forward_resource,
275277
enable_cimd=enable_cimd,
276278
)
277279

src/fastmcp/server/auth/providers/github.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def __init__(
220220
jwt_signing_key: str | bytes | None = None,
221221
require_authorization_consent: bool | Literal["external"] = True,
222222
consent_csp_policy: str | None = None,
223+
forward_resource: bool = True,
223224
http_client: httpx.AsyncClient | None = None,
224225
enable_cimd: bool = True,
225226
):
@@ -287,6 +288,7 @@ def __init__(
287288
jwt_signing_key=jwt_signing_key,
288289
require_authorization_consent=require_authorization_consent,
289290
consent_csp_policy=consent_csp_policy,
291+
forward_resource=forward_resource,
290292
enable_cimd=enable_cimd,
291293
)
292294

src/fastmcp/server/auth/providers/google.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ def __init__(
245245
jwt_signing_key: str | bytes | None = None,
246246
require_authorization_consent: bool | Literal["external"] = True,
247247
consent_csp_policy: str | None = None,
248+
forward_resource: bool = True,
248249
extra_authorize_params: dict[str, str] | None = None,
249250
http_client: httpx.AsyncClient | None = None,
250251
enable_cimd: bool = True,
@@ -347,6 +348,7 @@ def __init__(
347348
jwt_signing_key=jwt_signing_key,
348349
require_authorization_consent=require_authorization_consent,
349350
consent_csp_policy=consent_csp_policy,
351+
forward_resource=forward_resource,
350352
extra_authorize_params=extra_authorize_params_final,
351353
valid_scopes=valid_scopes_final,
352354
enable_cimd=enable_cimd,

0 commit comments

Comments
 (0)