freddyaboulton HF Staff commited on
Commit
dfd7bad
·
verified ·
1 Parent(s): e020ebe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -55
app.py CHANGED
@@ -24,7 +24,7 @@ mcp = FastMCP(
24
  # Auth settings for RFC 9728 Protected Resource Metadata
25
  auth=AuthSettings(
26
  issuer_url=AnyHttpUrl("https://huggingface.co/.well-known/oauth-authorization-server"), # Authorization Server URL
27
- resource_server_url=AnyHttpUrl("https://freddyaboulton-fastmcp-oauth.hf.space/"), # This server's URL
28
  required_scopes=["inference-api"],
29
  ),
30
  )
@@ -58,69 +58,69 @@ async def _():
58
  async def _():
59
  return RedirectResponse("/weather_mcp/.well-known/oauth-protected-resource")
60
 
61
- @app.get("/authorize")
62
- async def authorize_proxy(request: Request):
63
- """Forward GET requests to Hugging Face OAuth authorize endpoint"""
64
- target_url = "https://huggingface.co/oauth/authorize"
65
 
66
- async with httpx.AsyncClient() as client:
67
- # Prepare the request data
68
- headers = dict(request.headers)
69
- # Remove host header to avoid conflicts
70
- headers.pop("host", None)
71
 
72
- # Get query parameters
73
- query_params = str(request.url.query) if request.url.query else None
74
- target_url_with_params = f"{target_url}?{query_params}" if query_params else target_url
75
 
76
- # Forward the request
77
- response = await client.request(
78
- method=request.method,
79
- url=target_url_with_params,
80
- headers=headers,
81
- follow_redirects=False
82
- )
83
 
84
- # Return the response with the same status code, headers, and content
85
- return Response(
86
- content=response.content,
87
- status_code=response.status_code,
88
- headers=dict(response.headers)
89
- )
90
-
91
- @app.post("/register")
92
- async def register_proxy(request: Request):
93
- """Forward requests to Hugging Face OAuth register endpoint"""
94
- target_url = "https://huggingface.co/oauth/register"
95
 
96
- async with httpx.AsyncClient() as client:
97
- # Prepare the request data
98
- headers = dict(request.headers)
99
- # Remove host header to avoid conflicts
100
- headers.pop("host", None)
101
 
102
- # Get query parameters
103
- query_params = str(request.url.query) if request.url.query else None
104
- target_url_with_params = f"{target_url}?{query_params}" if query_params else target_url
105
 
106
- # Get request body if present
107
- body = await request.body()
108
 
109
- # Forward the request
110
- response = await client.request(
111
- method=request.method,
112
- url=target_url_with_params,
113
- headers=headers,
114
- content=body,
115
- follow_redirects=False
116
- )
117
 
118
- # Return the response with the same status code, headers, and content
119
- return Response(
120
- content=response.content,
121
- status_code=response.status_code,
122
- headers=dict(response.headers)
123
- )
124
 
125
 
126
 
 
24
  # Auth settings for RFC 9728 Protected Resource Metadata
25
  auth=AuthSettings(
26
  issuer_url=AnyHttpUrl("https://huggingface.co/.well-known/oauth-authorization-server"), # Authorization Server URL
27
+ resource_server_url=AnyHttpUrl("https://freddyaboulton-fastmcp-oauth.hf.space/weather_mcp"), # This server's URL
28
  required_scopes=["inference-api"],
29
  ),
30
  )
 
58
  async def _():
59
  return RedirectResponse("/weather_mcp/.well-known/oauth-protected-resource")
60
 
61
+ # @app.get("/authorize")
62
+ # async def authorize_proxy(request: Request):
63
+ # """Forward GET requests to Hugging Face OAuth authorize endpoint"""
64
+ # target_url = "https://huggingface.co/oauth/authorize"
65
 
66
+ # async with httpx.AsyncClient() as client:
67
+ # # Prepare the request data
68
+ # headers = dict(request.headers)
69
+ # # Remove host header to avoid conflicts
70
+ # headers.pop("host", None)
71
 
72
+ # # Get query parameters
73
+ # query_params = str(request.url.query) if request.url.query else None
74
+ # target_url_with_params = f"{target_url}?{query_params}" if query_params else target_url
75
 
76
+ # # Forward the request
77
+ # response = await client.request(
78
+ # method=request.method,
79
+ # url=target_url_with_params,
80
+ # headers=headers,
81
+ # follow_redirects=False
82
+ # )
83
 
84
+ # # Return the response with the same status code, headers, and content
85
+ # return Response(
86
+ # content=response.content,
87
+ # status_code=response.status_code,
88
+ # headers=dict(response.headers)
89
+ # )
90
+
91
+ # @app.post("/register")
92
+ # async def register_proxy(request: Request):
93
+ # """Forward requests to Hugging Face OAuth register endpoint"""
94
+ # target_url = "https://huggingface.co/oauth/register"
95
 
96
+ # async with httpx.AsyncClient() as client:
97
+ # # Prepare the request data
98
+ # headers = dict(request.headers)
99
+ # # Remove host header to avoid conflicts
100
+ # headers.pop("host", None)
101
 
102
+ # # Get query parameters
103
+ # query_params = str(request.url.query) if request.url.query else None
104
+ # target_url_with_params = f"{target_url}?{query_params}" if query_params else target_url
105
 
106
+ # # Get request body if present
107
+ # body = await request.body()
108
 
109
+ # # Forward the request
110
+ # response = await client.request(
111
+ # method=request.method,
112
+ # url=target_url_with_params,
113
+ # headers=headers,
114
+ # content=body,
115
+ # follow_redirects=False
116
+ # )
117
 
118
+ # # Return the response with the same status code, headers, and content
119
+ # return Response(
120
+ # content=response.content,
121
+ # status_code=response.status_code,
122
+ # headers=dict(response.headers)
123
+ # )
124
 
125
 
126