This repository has been archived by the owner on Mar 2, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
iglogin.py
82 lines (77 loc) · 3.02 KB
/
iglogin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import asyncio
import base64
import datetime
import getpass
import logging
import zlib
from mauigpapi import AndroidAPI, AndroidState
from mauigpapi.errors import IGChallengeError, IGLoginTwoFactorRequiredError
from mautrix.util.logging import TraceLogger
async def main():
logging.basicConfig(level=logging.DEBUG)
username = password = twofactor = None
while not username:
username = input("Username: ").strip()
state = AndroidState()
state.device.generate(username + str(datetime.date.today()))
api_log: TraceLogger = logging.getLogger("api")
api = AndroidAPI(state, log=api_log)
try:
print("Getting mobile config...")
await api.get_mobile_config()
while not password:
password = getpass.getpass("Password: ")
try:
try:
try:
print("Logging in...")
await api.login(username, password)
except IGLoginTwoFactorRequiredError as e:
print(e)
print("Enter `r` to re-request SMS")
inf = e.body.two_factor_info
while not twofactor:
twofactor = input("2FA code: ").lower().strip()
if twofactor == "r":
if inf.sms_two_factor_on:
print("Re-requesting SMS code...")
resp = await api.send_two_factor_login_sms(
username, identifier=inf.two_factor_identifier
)
print("SMS code re-requested")
inf = resp.two_factor_info
inf.totp_two_factor_on = False
else:
print("You don't have SMS 2FA on 🤔")
twofactor = None
print("Sending 2FA code...")
await api.two_factor_login(
username,
code=twofactor,
identifier=inf.two_factor_identifier,
is_totp=inf.totp_two_factor_on,
)
print("Fetching current user...")
user = await api.current_user()
except IGChallengeError as e:
print(e)
print("Resetting challenge...")
await api.challenge_auto(reset=True)
print("Fetching current user...")
user = await api.current_user()
except Exception as e:
print("💥", e)
return
if not user or not user.user:
print("Login failed?")
return
print(f"Logged in as @{user.user.username}")
print()
print(
base64.b64encode(zlib.compress(state.json().encode("utf-8"), level=9)).decode("utf-8")
)
print()
finally:
await api.http.close()
if __name__ == "__main__":
asyncio.run(main())