|
1 | 1 | import argparse |
| 2 | +import threading |
| 3 | + |
2 | 4 | import requests |
3 | 5 | import webbrowser |
4 | 6 | from http.server import BaseHTTPRequestHandler, HTTPServer |
@@ -36,17 +38,23 @@ def do_GET(self) -> None: |
36 | 38 | self.send_header("Content-type", "text/plain") |
37 | 39 | self.end_headers() |
38 | 40 | self.wfile.write(b"Authentication successful! You may close this window and return to the terminal.") |
39 | | - print("Authentication successful!") |
40 | | - print(f"Access Token: {access_token}") |
41 | | - self.server.shutdown() # Stop the server after successful auth |
| 41 | + print("Authenticated! Here's your access token:") |
| 42 | + print(access_token) |
42 | 43 | else: |
43 | 44 | self.send_response(400) |
44 | 45 | self.end_headers() |
45 | 46 | self.wfile.write(b"Invalid request") |
| 47 | + print("Authentication failed! Please try again.") |
46 | 48 | else: |
47 | 49 | self.send_response(404) |
48 | 50 | self.end_headers() |
49 | 51 | self.wfile.write(b"Not Found") |
| 52 | + print("Not Found") |
| 53 | + |
| 54 | + threading.Thread(target=self.server.shutdown, daemon=True).start() # Stop the server after handling the request |
| 55 | + |
| 56 | + def log_message(self, format, *args): |
| 57 | + pass |
50 | 58 |
|
51 | 59 |
|
52 | 60 | class AuthManager: |
@@ -81,9 +89,9 @@ def start_authentication(api_key: str, port: int = 8714) -> None: |
81 | 89 | HANDLER_CLASS = AuthHandler |
82 | 90 | with HTTPServer(SERVER_ADDRESS, HANDLER_CLASS) as server: |
83 | 91 | login_url = AuthManager.get_login_url(api_key) |
84 | | - print("Waiting for authentication...") |
| 92 | + print("\nWaiting for authentication...\n") |
85 | 93 | print("Visit the following URL to authenticate:") |
86 | | - print(login_url) |
| 94 | + print(login_url + "\n") |
87 | 95 | webbrowser.open(login_url) |
88 | 96 | server.serve_forever() |
89 | 97 |
|
|
0 commit comments