MCPcopy Create free account
hub / github.com/su-kaka/gcli2api / AuthCallbackHandler

Class AuthCallbackHandler

src/auth.py:198–230  ·  view source on GitHub ↗

OAuth回调处理器

Source from the content-addressed store, hash-verified

196
197
198class AuthCallbackHandler(BaseHTTPRequestHandler):
199 """OAuth回调处理器"""
200
201 def do_GET(self):
202 query_components = parse_qs(urlparse(self.path).query)
203 code = query_components.get("code", [None])[0]
204 state = query_components.get("state", [None])[0]
205
206 log.info(f"收到OAuth回调: code={'已获取' if code else '未获取'}, state={state}")
207
208 if code and state and state in auth_flows:
209 # 更新流程状态
210 auth_flows[state]["code"] = code
211 auth_flows[state]["completed"] = True
212
213 log.info(f"OAuth回调成功处理: state={state}")
214
215 self.send_response(200)
216 self.send_header("Content-type", "text/html")
217 self.end_headers()
218 # 成功页面
219 self.wfile.write(
220 b"<h1>OAuth authentication successful!</h1><p>You can close this window. Please return to the original page and click 'Get Credentials' button.</p>"
221 )
222 else:
223 self.send_response(400)
224 self.send_header("Content-type", "text/html")
225 self.end_headers()
226 self.wfile.write(b"<h1>Authentication failed.</h1><p>Please try again.</p>")
227
228 def log_message(self, format, *args):
229 # 减少日志噪音
230 pass
231
232
233async def create_auth_url(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected