From 6c5a9d6fb90ad8e71fc1a86c48c109944cbcedec Mon Sep 17 00:00:00 2001 From: Colin Panisset Date: Fri, 28 Feb 2020 09:06:10 +1100 Subject: [PATCH 1/6] Fixes for new google login page (issue #164) --- aws_google_auth/_version.py | 2 +- aws_google_auth/google.py | 41 +++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/aws_google_auth/_version.py b/aws_google_auth/_version.py index 667c8b5..9621eef 100644 --- a/aws_google_auth/_version.py +++ b/aws_google_auth/_version.py @@ -1 +1 @@ -__version__ = "0.0.33" +__version__ = "0.0.34" diff --git a/aws_google_auth/google.py b/aws_google_auth/google.py index 2cc1fb0..31bd030 100644 --- a/aws_google_auth/google.py +++ b/aws_google_auth/google.py @@ -221,24 +221,31 @@ def do_login(self): self.session.headers['Referer'] = sess.url + with open("/tmp/sess-text.html", "w") as fp: + fp.write(sess.text) + # Collect ProfileInformation, SessionState, signIn, and Password Challenge URL challenge_page = BeautifulSoup(sess.text, 'html.parser') - profile_information = challenge_page.find('input', { - 'name': 'ProfileInformation' - }).get('value') - session_state = challenge_page.find('input', { - 'name': 'SessionState' - }).get('value') - sign_in = challenge_page.find('input', {'name': 'signIn'}).get('value') - passwd_challenge_url = challenge_page.find('form', { - 'id': 'gaia_loginform' - }).get('action') + + # Handle the "old-style" page + if challenge_page.find('form', {'id': 'gaia_loginform'}): + form = challenge_page.find('form', {'id':'gaia_loginform'}) + passwd_challenge_url = form.get('action') + else: + # sometimes they serve up a different page + logging.info("Handling new-style login page") + form = challenge_page.find('form', {'id':'challenge'}) + passwd_challenge_url = 'https://accounts.google.com' + form.get('action') + + for input in form.find_all('input'): + if input.get('name') is None: + continue + + payload[input.get('name')] = input.get('value') + # Update the payload - payload['SessionState'] = session_state - payload['ProfileInformation'] = profile_information - payload['signIn'] = sign_in payload['Passwd'] = self.config.password # POST to Authenticate Password @@ -255,11 +262,9 @@ def do_login(self): raise ExpectedGoogleException('Invalid username or password') if "signin/rejected" in sess.url: - raise ExpectedGoogleException(u'''Default value of parameter `bgresponse` has not been accepted. - First, make sure you are logged out from AWS (or use an incognito browser session). Then, visit - the login URL at {}. - Open the web inspector and execute document.bg.invoke() in the console. Then, set --bg-response or - $GOOGLE_BG_RESPONSE to the function output.'''.format(self.login_url)) + raise ExpectedGoogleException(u'''Default value of parameter `bgresponse` has not accepted. + Please visit login URL {}, open the web inspector and execute document.bg.invoke() in the console. + Then, set --bg-response to the function output.'''.format(self.login_url)) self.check_extra_step(response_page) From ce4e78663691f000d3c7ed6b8ff8fe83bf129a6e Mon Sep 17 00:00:00 2001 From: Colin Panisset Date: Fri, 28 Feb 2020 09:07:32 +1100 Subject: [PATCH 2/6] Remove debugggery --- aws_google_auth/google.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/aws_google_auth/google.py b/aws_google_auth/google.py index 31bd030..6be26f3 100644 --- a/aws_google_auth/google.py +++ b/aws_google_auth/google.py @@ -221,9 +221,6 @@ def do_login(self): self.session.headers['Referer'] = sess.url - with open("/tmp/sess-text.html", "w") as fp: - fp.write(sess.text) - # Collect ProfileInformation, SessionState, signIn, and Password Challenge URL challenge_page = BeautifulSoup(sess.text, 'html.parser') From d5fea1ff671722564b52a05d36232eb08e13ab82 Mon Sep 17 00:00:00 2001 From: Colin Panisset Date: Fri, 28 Feb 2020 09:11:13 +1100 Subject: [PATCH 3/6] Address flake moans --- aws_google_auth/google.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/aws_google_auth/google.py b/aws_google_auth/google.py index 6be26f3..ab32fd1 100644 --- a/aws_google_auth/google.py +++ b/aws_google_auth/google.py @@ -224,7 +224,6 @@ def do_login(self): # Collect ProfileInformation, SessionState, signIn, and Password Challenge URL challenge_page = BeautifulSoup(sess.text, 'html.parser') - # Handle the "old-style" page if challenge_page.find('form', {'id': 'gaia_loginform'}): form = challenge_page.find('form', {'id':'gaia_loginform'}) @@ -235,11 +234,11 @@ def do_login(self): form = challenge_page.find('form', {'id':'challenge'}) passwd_challenge_url = 'https://accounts.google.com' + form.get('action') - for input in form.find_all('input'): - if input.get('name') is None: + for tag in form.find_all('input'): + if tag.get('name') is None: continue - payload[input.get('name')] = input.get('value') + payload[tag.get('name')] = tag.get('value') # Update the payload From 1590c6b55d40af9021d9c2278e0572d7205b5515 Mon Sep 17 00:00:00 2001 From: Colin Panisset Date: Fri, 28 Feb 2020 09:11:31 +1100 Subject: [PATCH 4/6] Add python 3.7 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 45fd83c..cf1d3aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ python: - "2.7" - "3.5" - "3.6" + - "3.7" sudo: false dist: trusty install: From 520bcfe64ce2e6ecfdb615dc7330d330f0493aff Mon Sep 17 00:00:00 2001 From: Colin Panisset Date: Fri, 28 Feb 2020 09:12:58 +1100 Subject: [PATCH 5/6] Revert add python 3.7 -- no support? --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cf1d3aa..45fd83c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ python: - "2.7" - "3.5" - "3.6" - - "3.7" sudo: false dist: trusty install: From efe035af16e641ad74d2603b3a5aa84dc0ea1ac3 Mon Sep 17 00:00:00 2001 From: Colin Panisset Date: Fri, 28 Feb 2020 09:16:32 +1100 Subject: [PATCH 6/6] More flake fixes --- aws_google_auth/google.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/aws_google_auth/google.py b/aws_google_auth/google.py index ab32fd1..b5df6fd 100644 --- a/aws_google_auth/google.py +++ b/aws_google_auth/google.py @@ -226,12 +226,12 @@ def do_login(self): # Handle the "old-style" page if challenge_page.find('form', {'id': 'gaia_loginform'}): - form = challenge_page.find('form', {'id':'gaia_loginform'}) + form = challenge_page.find('form', {'id': 'gaia_loginform'}) passwd_challenge_url = form.get('action') else: # sometimes they serve up a different page logging.info("Handling new-style login page") - form = challenge_page.find('form', {'id':'challenge'}) + form = challenge_page.find('form', {'id': 'challenge'}) passwd_challenge_url = 'https://accounts.google.com' + form.get('action') for tag in form.find_all('input'): @@ -240,7 +240,6 @@ def do_login(self): payload[tag.get('name')] = tag.get('value') - # Update the payload payload['Passwd'] = self.config.password