From 5d079bcf1af53d8993da525a10e5cefdf115793c Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Mon, 13 Dec 2021 19:17:14 -0300 Subject: Prototype function for obtaining Consent (it works) --- game/python-extra/tmw/__init__.py | 3 ++ game/python-extra/tmw/google.py | 71 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 game/python-extra/tmw/__init__.py create mode 100644 game/python-extra/tmw/google.py diff --git a/game/python-extra/tmw/__init__.py b/game/python-extra/tmw/__init__.py new file mode 100644 index 0000000..9c76689 --- /dev/null +++ b/game/python-extra/tmw/__init__.py @@ -0,0 +1,3 @@ +# TMW Plugin, both built-in client as Google Auth workaround + + diff --git a/game/python-extra/tmw/google.py b/game/python-extra/tmw/google.py new file mode 100644 index 0000000..3f240ee --- /dev/null +++ b/game/python-extra/tmw/google.py @@ -0,0 +1,71 @@ +import BaseHTTPServer, json, webbrowser, threading, time, traceback +import urlparse as parse +#from urllib.parse import urlparse + +REPLY = False +CODE = "" +PORT = 64004 # FIXME ask OS for a random port + +class GHandler(BaseHTTPServer.BaseHTTPRequestHandler): + def _set_headers(self, code=200): + self.send_response(code) + self.send_header('Content-type', 'text/html; charset=UTF-8') + self.end_headers() + + # We only need the GET method + def do_GET(self): + global REPLY, CODE + try: + # Snippet Source: StackOverflow/21584545 + post_data = dict(parse.parse_qsl(parse.urlsplit(self.path).query)) + # End Snippet + # Handle data... + + ## Verify for consent failure + if "error" in post_data: + print("ERROR DETECTED") + REPLY=True + raise Exception("Declined") + + ## Validate UUID + # assert post_data["uuid"] == UUID + # assert post_data["token"] == TOKEN + assert post_data["scope"] == "email%20https://www.googleapis.com/auth/userinfo.email%20openid" + CODE = post_data["code"] + # We're done + REPLY = True + self.send_response(200) + self.end_headers() + self.wfile.write("""Mana Launcher

Thanks


You can close this window now.""") + except: + traceback.print_exc() + # Garbage, disregard + self.send_error(403) + return + +# Wait for reply +def __callbacks__(): + global REPLY + server_address = ('', 64004) + httpd = BaseHTTPServer.HTTPServer(server_address, GHandler) + while not REPLY: + httpd.handle_request() + # Reply obtained, propagate + # FIXME + +def __request__(UUID, TOKEN): + global PORT, REPLY, CODE + # Fire loopback server + lo=threading.Thread(target=__callbacks__) + lo.daemon=True + lo.start() + + # OAuth Consent Screen + webbrowser.open_new("https://accounts.google.com/o/oauth2/v2/auth?scope=email&response_type=code&state=uuid%3D"+str(UUID)+"%26token%3D"+str(TOKEN)+"&redirect_uri=http%3A//127.0.0.1%3A"+str(PORT)+"&client_id=160252006716-mp7sgnncdtd4c9quv9sbtem3bkccn72q.apps.googleusercontent.com") + + # Wait until we get a reply + while not REPLY: + time.sleep(0.5) + + return CODE + -- cgit v1.2.3-70-g09d2