Skip to content

Commit

Permalink
Merge pull request subzeroid#3 from Jmallone/patch-1
Browse files Browse the repository at this point in the history
Update auth.py
  • Loading branch information
Stiveknx authored Mar 4, 2022
2 parents dee1854 + 4775b46 commit f7d19d3
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@
from typing import Optional, Dict
from fastapi import APIRouter, Depends, Form
from dependencies import ClientStorage, get_clients
from instagrapi.exceptions import (
ChallengeRequired
)


router = APIRouter(
prefix="/auth",
tags=["auth"],
responses={404: {"description": "Not found"}}
)

def handle_exception(client, e):
if isinstance(e, ChallengeRequired):
print("------ Challenge required \n\n")
api_path = client.last_json['challenge']['api_path']
client.set_challenge_url(api_path);
print(client.get_settings());

def challenge_code_handler(username, choice, challenge_url, session=None):
# Aqui salva o challenge_url e os headers e os cookies que tão nessa session
print(f"username:{username} \n CHOICE:{choice}")
print(f"URL:{challenge_url} \n session {session}")

return False
return True

@router.post("/login")
async def auth_login(username: str = Form(...),
Expand All @@ -27,8 +32,11 @@ async def auth_login(username: str = Form(...),
clients: ClientStorage = Depends(get_clients)) -> str:
"""Login by username and password with 2FA
"""


cl = clients.client()
cl.challenge_code_handler = challenge_code_handler

cl.handle_exception = handle_exception

if proxy != "":
cl.set_proxy(proxy)
Expand All @@ -44,6 +52,8 @@ async def auth_login(username: str = Form(...),
password,
verification_code=verification_code
)


if result:
clients.set(cl)
return cl.sessionid
Expand All @@ -70,7 +80,6 @@ async def challenge_code(sessionid: str = Form(...),
## Aqui você puxa os headers, os cookies e o challenge_url que você salvou na linha 14 e chama o checkpoint_resume
old_session = ""
challenge_url = ""

if(old_session):
result = cl.resume_checkpoint(code, challenge_url, old_session)
else:
Expand Down

0 comments on commit f7d19d3

Please sign in to comment.