@@ -127,8 +127,6 @@ async def authorize(
127
127
}
128
128
129
129
consent_url = f"{ self .settings .server_url } consent?{ urlencode (consent_params )} "
130
- print (f"[DEBUGG] { consent_url } { state } " )
131
-
132
130
return consent_url
133
131
134
132
async def handle_github_callback (self , code : str , state : str ) -> str :
@@ -277,10 +275,15 @@ async def revoke_token(
277
275
del self .tokens [token ]
278
276
279
277
280
- @dataclass
281
278
class ConsentHandler :
282
- provider : OAuthAuthorizationServerProvider [Any , Any , Any ]
283
- settings : ServerSettings
279
+
280
+
281
+
282
+ def __init__ (self , provider : SimpleGitHubOAuthProvider , settings : ServerSettings , path : str ):
283
+ self .provider : SimpleGitHubOAuthProvider = provider
284
+ self .settings : ServerSettings = settings
285
+ self .client_consent : dict [str , bool ] = {}
286
+ self .path = path
284
287
285
288
async def handle (self , request : Request ) -> Response :
286
289
# This handles both showing the consent form (GET) and processing consent (POST)
@@ -308,11 +311,11 @@ async def _show_consent_form(self, request: Request) -> HTMLResponse:
308
311
if client and hasattr (client , 'client_name' ):
309
312
client_name = client .client_name
310
313
311
- # TODO: get this passed in
312
- target_url = "/consent"
314
+ target_url = self .path
313
315
314
- # Create a simple consent form
316
+ # TODO: allow skipping consent if we've already approved this client ID
315
317
318
+ # Create a simple consent form
316
319
html_content = f"""
317
320
<!DOCTYPE html>
318
321
<html>
@@ -436,9 +439,7 @@ async def _process_consent(self, request: Request) -> RedirectResponse | HTMLRes
436
439
if client_id :
437
440
client = await self .provider .get_client (client_id )
438
441
if client :
439
- # TODO: move this out of provider
440
- await self .provider .grant_client_consent (client )
441
-
442
+ self .client_consent [client .client_id ] = True
442
443
443
444
auth_url = (
444
445
f"{ self .settings .github_auth_url } "
@@ -505,8 +506,6 @@ def create_simple_mcp_server(settings: ServerSettings) -> FastMCP:
505
506
enabled = True ,
506
507
valid_scopes = [settings .mcp_scope ],
507
508
default_scopes = [settings .mcp_scope ],
508
- # Turning off consent since we'll handle it via custom endpoint
509
- client_consent_required = False
510
509
),
511
510
required_scopes = [settings .mcp_scope ],
512
511
)
@@ -521,9 +520,10 @@ def create_simple_mcp_server(settings: ServerSettings) -> FastMCP:
521
520
auth = auth_settings ,
522
521
)
523
522
524
- consent_handler = ConsentHandler (provider = oauth_provider , settings = settings )
523
+ consent_path = "/consent"
524
+ consent_handler = ConsentHandler (provider = oauth_provider , settings = settings , path = consent_path )
525
525
526
- @app .custom_route ("/consent" , methods = ["GET" , "POST" ])
526
+ @app .custom_route (consent_path , methods = ["GET" , "POST" ])
527
527
async def example_consent_handler (request : Request ) -> Response :
528
528
return await consent_handler .handle (request )
529
529
0 commit comments