@@ -108,7 +108,11 @@ def login(username=None, password=None, expiresIn=86400, scope='internal', by_sm
108108 'scope' : scope ,
109109 'username' : username ,
110110 'challenge_type' : challenge_type ,
111- 'device_token' : device_token
111+ 'device_token' : device_token ,
112+ 'try_passkeys' : False ,
113+ 'token_request_path' :'/login' ,
114+ 'create_read_only_secondary_token' :True ,
115+ 'request_id' : '848bd19e-02bc-45d9-99b5-01bce5a79ea7'
112116 }
113117
114118 if mfa_code :
@@ -181,6 +185,10 @@ def login(username=None, password=None, expiresIn=86400, scope='internal', by_sm
181185 update_session (
182186 'X-ROBINHOOD-CHALLENGE-RESPONSE-ID' , challenge_id )
183187 data = request_post (url , payload )
188+ elif 'verification_workflow' in data :
189+ workflow_id = data ['verification_workflow' ]['id' ]
190+ _validate_sherrif_id (device_token = device_token , workflow_id = workflow_id , mfa_code = mfa_code )
191+ data = request_post (url , payload )
184192 # Update Session data with authorization or raise exception with the information present in data.
185193 if 'access_token' in data :
186194 token = '{0} {1}' .format (data ['token_type' ], data ['access_token' ])
@@ -193,12 +201,49 @@ def login(username=None, password=None, expiresIn=86400, scope='internal', by_sm
193201 'access_token' : data ['access_token' ],
194202 'refresh_token' : data ['refresh_token' ],
195203 'device_token' : payload ['device_token' ]}, f )
204+
196205 else :
197- raise Exception (data ['detail' ])
206+ if 'detail' in data :
207+ raise Exception (data ['detail' ])
208+ raise Exception (f"Received an error response { data } " )
198209 else :
199210 raise Exception ('Error: Trouble connecting to robinhood API. Check internet connection.' )
200211 return (data )
201212
213+ def _validate_sherrif_id (device_token :str , workflow_id :str ,mfa_code :str ):
214+ url = "https://api.robinhood.com/pathfinder/user_machine/"
215+ payload = {
216+ 'device_id' : device_token ,
217+ 'flow' : 'suv' ,
218+ 'input' :{'workflow_id' : workflow_id }
219+ }
220+ data = request_post (url = url , payload = payload ,json = True )
221+ if "id" in data :
222+ inquiries_url = f"https://api.robinhood.com/pathfinder/inquiries/{ data ['id' ]} /user_view/"
223+ res = request_get (inquiries_url )
224+ challenge_id = res ['type_context' ]["context" ]["sheriff_challenge" ]["id" ]
225+ challenge_url = f"https://api.robinhood.com/challenge/{ challenge_id } /respond/"
226+ challenge_payload = {
227+ 'response' : mfa_code
228+ }
229+ challenge_response = request_post (url = challenge_url , payload = challenge_payload ,json = True )
230+ if challenge_response ["status" ] == "validated" :
231+ inquiries_payload = {"sequence" :0 ,"user_input" :{"status" :"continue" }}
232+ inquiries_response = request_post (url = inquiries_url , payload = inquiries_payload ,json = True )
233+ if inquiries_response ["type_context" ]["result" ] == "workflow_status_approved" :
234+ return
235+ else :
236+ raise Exception ("workflow status not approved" )
237+ else :
238+ raise Exception ("Challenge not validated" )
239+ raise Exception ("Id not returned in user-machine call" )
240+
241+ def _get_sherrif_challenge (token_id :str ):
242+
243+ if "id" in data :
244+ return data ["id" ]
245+ raise Exception ("Id not returned in user-machine call" )
246+
202247
203248@login_required
204249def logout ():
0 commit comments