Skip to content

Commit 49c4892

Browse files
authored
Merge pull request game-by-virtuals#107 from game-by-virtuals/plugin/yang-game-twitter-auth-enhancement
[Plugin] Enhance Game Twitter Plugin Auth Server Shutdown
2 parents c2be557 + 577cb34 commit 49c4892

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

plugins/twitter/twitter_plugin_gamesdk/game_twitter_auth.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import argparse
2+
import threading
3+
24
import requests
35
import webbrowser
46
from http.server import BaseHTTPRequestHandler, HTTPServer
@@ -36,17 +38,23 @@ def do_GET(self) -> None:
3638
self.send_header("Content-type", "text/plain")
3739
self.end_headers()
3840
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)
4243
else:
4344
self.send_response(400)
4445
self.end_headers()
4546
self.wfile.write(b"Invalid request")
47+
print("Authentication failed! Please try again.")
4648
else:
4749
self.send_response(404)
4850
self.end_headers()
4951
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
5058

5159

5260
class AuthManager:
@@ -81,9 +89,9 @@ def start_authentication(api_key: str, port: int = 8714) -> None:
8189
HANDLER_CLASS = AuthHandler
8290
with HTTPServer(SERVER_ADDRESS, HANDLER_CLASS) as server:
8391
login_url = AuthManager.get_login_url(api_key)
84-
print("Waiting for authentication...")
92+
print("\nWaiting for authentication...\n")
8593
print("Visit the following URL to authenticate:")
86-
print(login_url)
94+
print(login_url + "\n")
8795
webbrowser.open(login_url)
8896
server.serve_forever()
8997

0 commit comments

Comments
 (0)