-
Notifications
You must be signed in to change notification settings - Fork 0
/
oauth.py
47 lines (38 loc) · 1.41 KB
/
oauth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import urlparse
import data
import threading
# Have one instance of the server running only
running=False
hostName = "localhost"
serverPort = 8080
class AuthenticationLoopback(BaseHTTPRequestHandler):
def do_GET(self):
query = urlparse(self.path).query
query_components = dict(qc.split("=") for qc in query.split("&"))
data.OAUTH_TOKEN = query_components["token"]
if data.OAUTH_TOKEN=="Failed":
data.Settings.valid_oauth=False
data.OAUTH_TOKEN=None
else:
data.Settings.valid_oauth=True
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(bytes("<html><head><title>Success!</title></head>", "utf-8"))
self.wfile.write(bytes("<body>", "utf-8"))
self.wfile.write(bytes("<p>You may close this tab and return to the osu assistant application now.</p>", "utf-8"))
self.wfile.write(bytes("</body></html>", "utf-8"))
fin()
webServer = HTTPServer((hostName, serverPort), AuthenticationLoopback)
def fin():
global running
running=False
webServer.shutdown()
def ask_token():
global running
if not running:
thread = threading.Thread(target = webServer.serve_forever)
thread.daemon=True
thread.start()
running=True