Skip to content

Commit

Permalink
do call to authorization api
Browse files Browse the repository at this point in the history
given it requires 2FA, the generate token call is going to fail
but thats going to send 2FA code properly
  • Loading branch information
techgaun committed Jun 21, 2017
1 parent 12996c5 commit 421aefd
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doctr/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ def GitHub_login(*, username=None, password=None, OTP=None, headers=None):
if r.status_code == 401:
two_factor = r.headers.get('X-GitHub-OTP')
if two_factor:
auth_header = base64.urlsafe_b64encode(bytes(username + ':' + password, 'utf8')).decode()
login_kwargs = {'auth': None, 'headers': {'Authorization': 'Basic {}'.format(auth_header)}}
try:
generate_GitHub_token(**login_kwargs)
except requests.exceptions.HTTPError:
pass
print("A two-factor authentication code is required:", two_factor.split(';')[1].strip())
OTP = input("Authentication code: ")
return GitHub_login(username=username, password=password, OTP=OTP, headers=headers)
Expand Down

0 comments on commit 421aefd

Please sign in to comment.