From 8a3b9ef97845ddb51940f7a51f87e8ddca363b66 Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Mon, 13 Dec 2021 21:43:35 -0300 Subject: Prototype version --- game/python-extra/tmw/google.py | 13 +++++++++++-- game/update.rpy | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/game/python-extra/tmw/google.py b/game/python-extra/tmw/google.py index 3f240ee..4722a2d 100644 --- a/game/python-extra/tmw/google.py +++ b/game/python-extra/tmw/google.py @@ -30,6 +30,7 @@ class GHandler(BaseHTTPServer.BaseHTTPRequestHandler): ## Validate UUID # assert post_data["uuid"] == UUID # assert post_data["token"] == TOKEN + # FIXME: Unreliable? assert post_data["scope"] == "email%20https://www.googleapis.com/auth/userinfo.email%20openid" CODE = post_data["code"] # We're done @@ -53,7 +54,7 @@ def __callbacks__(): # Reply obtained, propagate # FIXME -def __request__(UUID, TOKEN): +def __request__(UUID, TOKEN, LOGIN): global PORT, REPLY, CODE # Fire loopback server lo=threading.Thread(target=__callbacks__) @@ -61,7 +62,8 @@ def __request__(UUID, TOKEN): 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") + 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&login_hint="+str(LOGIN)) + # TODO: Maybe supply login_hint with the first part of the login (before the "@"). Google may end up doing everything this way? # Wait until we get a reply while not REPLY: @@ -69,3 +71,10 @@ def __request__(UUID, TOKEN): return CODE +def __reset__(): + global REPLY, CODE + REPLY = False + CODE = "" + return + + diff --git a/game/update.rpy b/game/update.rpy index 626c41a..b0a46a9 100644 --- a/game/update.rpy +++ b/game/update.rpy @@ -286,10 +286,46 @@ init python: ############################################################################# def auth_google(): global vaultId, vaultToken, responsive - status_update(_("Not yet implemented."), 80) - responsive = False + status_update(_("Loading Google Auth..."), 80) + from tmw import google + status_update(_("Google Auth loaded."), 81) + # FIXME + if persistent.email is None: + responsive=False + return + #renpy.call_in_new_context("gimmemail") + status_update(_("Requesting OAuth consent..."), 85) + # FIXME - Generate a Token for cross forgery? + # FIXME - Try to login first? + code = google.__request__("UUID", "TOKEN", persistent.email) + google.__reset__() + status_update(_("Contacting Vault..."), 90) + auth = {"mail": persistent.email+"@gmail.com", "oper": code} + r = vault.post(VAULT_HOST+"/google_auth", json=auth, timeout=15.0) + ## If unsucessful, give up on Google Auth + if (r.status_code != 200): + status_update(_("Vault returned code %d" % r.status_code), 90) + responsive = False + return + status_update(_("Completing login..."), 95) + + auth2 = r.json() + vaultId = auth2["vaultId"] + vaultToken = auth2["token"] + status_update(pc=100) return +label gimmemail: + # Request email if not saved + while persistent.email is None: + call screen register_input("Please input your Google ID:") + #persistent.email = renpy.call_screen("register_input", "Please input your Google ID:") + $ persistent.email = str(_return) + $ persistent.email = persistent.email.replace("@gmail.com", "") + if "@" in persistent.email: + $ persistent.email = None + return + ################################################################################# screen register_method(): ## Ensure other screens do not get input while this screen is displayed. -- cgit v1.2.3-70-g09d2