Skip to content

Commit

Permalink
Update auth_method for 2FA
Browse files Browse the repository at this point in the history
  • Loading branch information
aamazie authored May 6, 2019
1 parent 080584f commit eb741b3
Showing 1 changed file with 44 additions and 25 deletions.
69 changes: 44 additions & 25 deletions Robinhood/Robinhood.py
Original file line number Diff line number Diff line change
@@ -139,17 +139,13 @@ def login(self,
try:
res = self.session.post(endpoints.login(), data=payload, timeout=15)
data = res.json()
print(data)

if 'access_token' in data.keys() and 'refresh_token' in data.keys():
self.auth_token = data['access_token']
self.refresh_token = data['refresh_token']
self.headers['Authorization'] = 'Bearer ' + self.auth_token
return True

# if 'mfa_required' in data.keys():
# raise RH_exception.TwoFactorRequired()

except requests.exceptions.HTTPError:
raise RH_exception.LoginFailed()

@@ -199,29 +195,52 @@ def login(self,

def auth_method(self):

payload = {
'password': self.password,
'username': self.username,
'grant_type': 'password',
'client_id': "c82SH0WZOsabOXGP2sxqcj34FxkvfnWRZBKlBjFS",
'expires_in': '86400',
'scope': 'internal',
'device_token': self.device_token,
}

try:
res = self.session.post(endpoints.login(), data=payload, timeout=15)
res.raise_for_status()
data = res.json()
if self.mfa_code:
payload = {
'password': self.password,
'username': self.username,
'grant_type': 'password',
'client_id': "c82SH0WZOsabOXGP2sxqcj34FxkvfnWRZBKlBjFS",
'mfa_code': self.mfa_code
}

if 'access_token' in data.keys() and 'refresh_token' in data.keys():
self.auth_token = data['access_token']
self.refresh_token = data['refresh_token']
self.headers['Authorization'] = 'Bearer ' + self.auth_token
return True
try:
res = self.session.post(endpoints.login(), data=payload, timeout=15)
data = res.json()

if 'access_token' in data.keys() and 'refresh_token' in data.keys():
self.auth_token = data['access_token']
self.refresh_token = data['refresh_token']
self.headers['Authorization'] = 'Bearer ' + self.auth_token
return True

except requests.exceptions.HTTPError:
raise RH_exception.LoginFailed()

except requests.exceptions.HTTPError:
raise RH_exception.LoginFailed()
else:
payload = {
'password': self.password,
'username': self.username,
'grant_type': 'password',
'client_id': "c82SH0WZOsabOXGP2sxqcj34FxkvfnWRZBKlBjFS",
'expires_in': '86400',
'scope': 'internal',
'device_token': self.device_token,
}

try:
res = self.session.post(endpoints.login(), data=payload, timeout=15)
res.raise_for_status()
data = res.json()

if 'access_token' in data.keys() and 'refresh_token' in data.keys():
self.auth_token = data['access_token']
self.refresh_token = data['refresh_token']
self.headers['Authorization'] = 'Bearer ' + self.auth_token
return True

except requests.exceptions.HTTPError:
raise RH_exception.LoginFailed()

return False

0 comments on commit eb741b3

Please sign in to comment.