HTTP handler that captures the OAuth2 authorization callback.
| 39 | |
| 40 | |
| 41 | class _CallbackHandler(BaseHTTPRequestHandler): |
| 42 | """HTTP handler that captures the OAuth2 authorization callback.""" |
| 43 | |
| 44 | callback_url = None |
| 45 | error = None |
| 46 | |
| 47 | def do_GET(self): |
| 48 | _CallbackHandler.callback_url = f"http://localhost:{_REDIRECT_PORT}{self.path}" |
| 49 | parsed = urlparse(self.path) |
| 50 | params = parse_qs(parsed.query) |
| 51 | |
| 52 | if "error" in params: |
| 53 | _CallbackHandler.error = params["error"][0] |
| 54 | self.send_response(400) |
| 55 | self.send_header("Content-Type", "text/html") |
| 56 | self.end_headers() |
| 57 | msg = params.get("error_description", [params["error"][0]])[0] |
| 58 | self.wfile.write( |
| 59 | f"<html><body><h1>Login failed</h1><p>{msg}</p></body></html>".encode() |
| 60 | ) |
| 61 | else: |
| 62 | self.send_response(200) |
| 63 | self.send_header("Content-Type", "text/html") |
| 64 | self.end_headers() |
| 65 | self.wfile.write( |
| 66 | b"<html><body><h1>Login successful!</h1>" |
| 67 | b"<p>You can close this window.</p></body></html>" |
| 68 | ) |
| 69 | |
| 70 | def log_message(self, format, *args): |
| 71 | pass |
| 72 | |
| 73 | |
| 74 | # ── OIDC discovery ────────────────────────────────────────────────── |
no outgoing calls
searching dependent graphs…