mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-03 12:21:35 +00:00
Allow user copy/paste retries in gam oauth create (#1488)
This commit is contained in:
@@ -20,6 +20,8 @@ import google_auth_oauthlib.flow
|
|||||||
import google.oauth2.credentials
|
import google.oauth2.credentials
|
||||||
import google.oauth2.id_token
|
import google.oauth2.id_token
|
||||||
|
|
||||||
|
from gam import controlflow
|
||||||
|
from gam import display
|
||||||
from gam import fileutils
|
from gam import fileutils
|
||||||
from gam import transport
|
from gam import transport
|
||||||
from gam.var import GM_Globals, GM_WINDOWS
|
from gam.var import GM_Globals, GM_WINDOWS
|
||||||
@@ -38,6 +40,8 @@ MESSAGE_LOCAL_SERVER_AUTHORIZATION_PROMPT = ('\nYour browser has been opened to'
|
|||||||
MESSAGE_LOCAL_SERVER_SUCCESS = ('The authentication flow has completed. You may'
|
MESSAGE_LOCAL_SERVER_SUCCESS = ('The authentication flow has completed. You may'
|
||||||
' close this browser window and return to GAM.')
|
' close this browser window and return to GAM.')
|
||||||
|
|
||||||
|
MESSAGE_AUTHENTICATION_COMPLETE = ('\nThe authentication flow has completed.\n')
|
||||||
|
|
||||||
|
|
||||||
class CredentialsError(Exception):
|
class CredentialsError(Exception):
|
||||||
"""Base error class."""
|
"""Base error class."""
|
||||||
@@ -531,7 +535,7 @@ def _localhost_to_ip():
|
|||||||
return local_ip
|
return local_ip
|
||||||
|
|
||||||
def _wait_for_http_client(d):
|
def _wait_for_http_client(d):
|
||||||
wsgi_app = google_auth_oauthlib.flow._RedirectWSGIApp('')
|
wsgi_app = google_auth_oauthlib.flow._RedirectWSGIApp(MESSAGE_LOCAL_SERVER_SUCCESS)
|
||||||
wsgiref.simple_server.WSGIServer.allow_reuse_address = False
|
wsgiref.simple_server.WSGIServer.allow_reuse_address = False
|
||||||
# Convert hostn to IP since apparently binding to the IP
|
# Convert hostn to IP since apparently binding to the IP
|
||||||
# reduces odds of firewall blocking us
|
# reduces odds of firewall blocking us
|
||||||
@@ -606,20 +610,31 @@ class _ShortURLFlow(google_auth_oauthlib.flow.InstalledAppFlow):
|
|||||||
d['auth_url'], _ = self.authorization_url(**kwargs)
|
d['auth_url'], _ = self.authorization_url(**kwargs)
|
||||||
print(f"URL is: {d['auth_url']}")
|
print(f"URL is: {d['auth_url']}")
|
||||||
user_input.start()
|
user_input.start()
|
||||||
|
userInput = False
|
||||||
while True:
|
while True:
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
if not http_client.is_alive():
|
if not http_client.is_alive():
|
||||||
user_input.terminate()
|
user_input.terminate()
|
||||||
break
|
break
|
||||||
elif not user_input.is_alive():
|
elif not user_input.is_alive():
|
||||||
|
userInput = True
|
||||||
http_client.terminate()
|
http_client.terminate()
|
||||||
break
|
break
|
||||||
|
while True:
|
||||||
code = d['code']
|
code = d['code']
|
||||||
if code.startswith('http'):
|
if code.startswith('http'):
|
||||||
parsed_url = urlparse(code)
|
parsed_url = urlparse(code)
|
||||||
parsed_params = parse_qs(parsed_url.query)
|
parsed_params = parse_qs(parsed_url.query)
|
||||||
code = parsed_params.get('code', [None])[0]
|
code = parsed_params.get('code', [None])[0]
|
||||||
|
try:
|
||||||
self.fetch_token(code=code)
|
self.fetch_token(code=code)
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
if not userInput:
|
||||||
|
controlflow.system_error_exit(8, str(e))
|
||||||
|
display.print_error(str(e))
|
||||||
|
_wait_for_user_input(d)
|
||||||
|
sys.stdout.write(MESSAGE_AUTHENTICATION_COMPLETE)
|
||||||
return self.credentials
|
return self.credentials
|
||||||
|
|
||||||
class _FileLikeThreadLock:
|
class _FileLikeThreadLock:
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import platform
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
GAM_AUTHOR = 'Jay Lee <jay0lee@gmail.com>'
|
GAM_AUTHOR = 'Jay Lee <jay0lee@gmail.com>'
|
||||||
GAM_VERSION = '6.15'
|
GAM_VERSION = '6.16'
|
||||||
GAM_LICENSE = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'
|
GAM_LICENSE = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'
|
||||||
|
|
||||||
GAM_URL = 'https://git.io/gam'
|
GAM_URL = 'https://git.io/gam'
|
||||||
|
|||||||
Reference in New Issue
Block a user