Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for one-time security codes #226

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ by this tool are:
| Dual prompt | ``.../signin/challenge/dp/...`` |
| (Validate 2FA ) | |
+------------------+-------------------------------------+
| One-time | ``.../signin/challenge/skotp/...`` |
| security codes | |
+------------------+-------------------------------------+
| Backup code | ``... (unknown yet) ...`` |
| (printed codes) | |
+------------------+-------------------------------------+
Expand Down
39 changes: 39 additions & 0 deletions aws_google_auth/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ def do_login(self):
sess = self.handle_iap(sess)
elif "challenge/dp/" in sess.url:
sess = self.handle_dp(sess)
elif "challenge/skotp/" in sess.url:
sess = self.handle_skotp(sess)
elif "challenge/ootp/5" in sess.url:
raise NotImplementedError(
'Offline Google App OOTP not implemented')
Expand Down Expand Up @@ -823,6 +825,41 @@ def handle_iap(self, sess):
# Submit SMS/VOICE token
return self.post(challenge_url, data=payload)

def handle_skotp(self, sess):
response_page = BeautifulSoup(sess.text, 'html.parser')
ltmpl = response_page.find('input', {'name': 'ltmpl'}).get('value')
flowname = response_page.find('input', {'name': 'flowName'}).get('value')
tl = response_page.find('input', {'name': 'TL'}).get('value')
gxf = response_page.find('input', {'name': 'gxf'}).get('value')
challenge_url = sess.url.split("?")[0]
challenge_id = challenge_url.split("skotp/")[1]

skotp_code = input("Enter https://g.co/sc one-time security code: ") or None

if not skotp_code:
raise ValueError(
"One-time security code required for {} but none supplied.".format(
self.config.username))

payload = {
'challengeId': challenge_id,
'challengeType': 37,
'continue': self.cont,
'ltmpl': ltmpl,
'scc': 1,
'sarp': 1,
'oauth': 1,
'flowName': flowname,
'faa': 1,
'TL': tl,
'gxf': gxf,
'Pin': skotp_code,
'TrustDevice': 'on',
}

# Submit SKOTP
return self.post(challenge_url, data=payload)

def handle_selectchallenge(self, sess):
response_page = BeautifulSoup(sess.text, 'html.parser')

Expand All @@ -838,6 +875,8 @@ def handle_selectchallenge(self, sess):
challenges.append(['SMS other phone', i.attrs.get("data-challengeentry")])
elif "challenge/sk/" in action:
challenges.append(['YubiKey', i.attrs.get("data-challengeentry")])
elif "challenge/skotp/" in action:
challenges.append(['One-time security code', i.attrs.get("data-challengeentry")])
elif "challenge/az/" in action:
challenges.append(['Google Prompt', i.attrs.get("data-challengeentry")])

Expand Down