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

fix #524: login with robinhood mfa #526

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 7 additions & 1 deletion robin_stocks/robinhood/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def login(username=None, password=None, expiresIn=86400, scope='internal', by_sm
'X-ROBINHOOD-CHALLENGE-RESPONSE-ID', challenge_id)
data = request_post(url, payload)
elif 'verification_workflow' in data:
mfa_code = input("Please type in the MFA code: ")
workflow_id = data['verification_workflow']['id']
_validate_sherrif_id(device_token=device_token, workflow_id=workflow_id, mfa_code=mfa_code)
data = request_post(url, payload)
Expand All @@ -210,14 +211,19 @@ def login(username=None, password=None, expiresIn=86400, scope='internal', by_sm
raise Exception('Error: Trouble connecting to robinhood API. Check internet connection.')
return(data)


def _validate_sherrif_id(device_token:str, workflow_id:str,mfa_code:str):
url = "https://api.robinhood.com/pathfinder/user_machine/"
payload = {
'device_id': device_token,
'flow': 'suv',
'input':{'workflow_id': workflow_id}
}
data = request_post(url=url, payload=payload,json=True)
data = request_post(url=url, payload=payload, json=True)
while (data.status_code != 200):
mfa_code = input(
"That MFA code was not correct. Please type in another MFA code: ")
data = request_post(url, payload, jsonify_data=False)
if "id" in data:
inquiries_url = f"https://api.robinhood.com/pathfinder/inquiries/{data['id']}/user_view/"
res = request_get(inquiries_url)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
long_description = f.read()

setup(name='robin_stocks',
version='3.3.0',
version='3.3.1',
description='A Python wrapper around the Robinhood API',
long_description=long_description,
long_description_content_type='text/x-rst',
Expand Down