MCPcopy Create free account
hub / github.com/mlco2/codecarbon / _CallbackHandler

Class _CallbackHandler

codecarbon/cli/auth.py:41–71  ·  view source on GitHub ↗

HTTP handler that captures the OAuth2 authorization callback.

Source from the content-addressed store, hash-verified

39
40
41class _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 ──────────────────────────────────────────────────

Callers 1

_make_handlerMethod · 0.90

Calls

no outgoing calls

Tested by 1

_make_handlerMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…