OAuth回调处理器
| 196 | |
| 197 | |
| 198 | class 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 | |
| 233 | async def create_auth_url( |
nothing calls this directly
no outgoing calls
no test coverage detected