oauth
This commit is contained in:
parent
9107e00bb2
commit
dd7f82ee0b
1 changed files with 68 additions and 52 deletions
114
app.py
114
app.py
|
@ -9,63 +9,79 @@ from os import environ
|
||||||
import imaplib
|
import imaplib
|
||||||
import email
|
import email
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
from os import path
|
||||||
# get previously known message ids from imap server
|
|
||||||
|
|
||||||
print('loggin into IMAP Server:', environ['IMAP_HOST'])
|
|
||||||
|
|
||||||
Mailbox = imaplib.IMAP4_SSL(environ['IMAP_HOST'])
|
|
||||||
Mailbox.login(environ['IMAP_USER'], environ['IMAP_PASSWORD'])
|
|
||||||
Mailbox.select()
|
|
||||||
typ, data = Mailbox.search(None, '(FROM "noreply@steampowered.com" SUBJECT "Your Steam account: Access from new web or mobile device")')
|
|
||||||
old_msg_ids = data[0].split()
|
|
||||||
|
|
||||||
# perform steam login
|
|
||||||
|
|
||||||
print('loggin into STEAM:', environ['STEAM_USERNAME'])
|
print('loggin into STEAM:', environ['STEAM_USERNAME'])
|
||||||
|
user = wa.MobileWebAuth(environ['STEAM_USERNAME'])
|
||||||
|
|
||||||
user = wa.WebAuth(environ['STEAM_USERNAME'])
|
# try oauth token
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user.login(environ['STEAM_PASSWORD'])
|
print('trying oauth login')
|
||||||
except (wa.LoginIncorrect) as exp:
|
|
||||||
print('ERROR: loggin incorrect')
|
|
||||||
raise
|
|
||||||
except (wa.CaptchaRequired) as exp:
|
|
||||||
print('ERROR: captcha required:', user.captcha_url)
|
|
||||||
#user.login(password=environ['STEAM_PASSWORD'], captcha=input("Captcha: "))
|
|
||||||
raise
|
|
||||||
except wa.TwoFactorCodeRequired:
|
|
||||||
print('ERROR: 2FA code required')
|
|
||||||
#user.login(twofactor_code=input("2FA Code: "))
|
|
||||||
raise
|
|
||||||
except wa.EmailCodeRequired:
|
|
||||||
print('getting email code')
|
|
||||||
while True:
|
|
||||||
typ, data = Mailbox.search(None, '(FROM "noreply@steampowered.com" SUBJECT "Your Steam account: Access from new web or mobile device")')
|
|
||||||
newest_msg_id = data[0].split()[-1]
|
|
||||||
|
|
||||||
if newest_msg_id in old_msg_ids:
|
with open('oauth_token', 'r') as file:
|
||||||
print('refreshing messages')
|
user.oauth_login(file.read(), steam_id=environ['STEAM_ID'], language='english')
|
||||||
sleep(1)
|
|
||||||
else:
|
|
||||||
print('messages received')
|
|
||||||
break
|
|
||||||
|
|
||||||
typ, data = Mailbox.fetch(newest_msg_id, '(RFC822)')
|
print('oauth login successful')
|
||||||
msg = email.message_from_bytes(data[0][1])
|
except (wa.LoginIncorrect, FileNotFoundError) as exp:
|
||||||
|
print('oauth login failed:', exp)
|
||||||
|
|
||||||
for payload in msg.get_payload():
|
# get previously known message ids from imap server
|
||||||
if (
|
|
||||||
payload.get_content_maintype() == 'text' and
|
|
||||||
payload.get_content_subtype() == 'plain'
|
|
||||||
):
|
|
||||||
plaintext_lines = payload.get_payload(decode=True).decode().splitlines()
|
|
||||||
code = plaintext_lines[plaintext_lines.index('Login Code') + 1]
|
|
||||||
break
|
|
||||||
|
|
||||||
print('code found:', code)
|
print('loggin into IMAP Server:', environ['IMAP_HOST'])
|
||||||
user.login(email_code=code)
|
|
||||||
|
Mailbox = imaplib.IMAP4_SSL(environ['IMAP_HOST'])
|
||||||
|
Mailbox.login(environ['IMAP_USER'], environ['IMAP_PASSWORD'])
|
||||||
|
Mailbox.select()
|
||||||
|
typ, data = Mailbox.search(None, '(FROM "noreply@steampowered.com" SUBJECT "Your Steam account: Access from new web or mobile device")')
|
||||||
|
old_msg_ids = data[0].split()
|
||||||
|
|
||||||
|
# perform steam login
|
||||||
|
|
||||||
|
try:
|
||||||
|
user.login(environ['STEAM_PASSWORD'])
|
||||||
|
except (wa.LoginIncorrect) as exp:
|
||||||
|
print('ERROR: loggin incorrect')
|
||||||
|
raise
|
||||||
|
except (wa.CaptchaRequired) as exp:
|
||||||
|
print('ERROR: captcha required:', user.captcha_url)
|
||||||
|
#user.login(password=environ['STEAM_PASSWORD'], captcha=input("Captcha: "))
|
||||||
|
raise
|
||||||
|
except wa.TwoFactorCodeRequired:
|
||||||
|
print('ERROR: 2FA code required')
|
||||||
|
#user.login(twofactor_code=input("2FA Code: "))
|
||||||
|
raise
|
||||||
|
except wa.EmailCodeRequired:
|
||||||
|
print('getting email code')
|
||||||
|
while True:
|
||||||
|
typ, data = Mailbox.search(None, '(FROM "noreply@steampowered.com" SUBJECT "Your Steam account: Access from new web or mobile device")')
|
||||||
|
newest_msg_id = data[0].split()[-1]
|
||||||
|
|
||||||
|
if newest_msg_id in old_msg_ids:
|
||||||
|
print('refreshing messages')
|
||||||
|
sleep(1)
|
||||||
|
else:
|
||||||
|
print('messages received')
|
||||||
|
break
|
||||||
|
|
||||||
|
typ, data = Mailbox.fetch(newest_msg_id, '(RFC822)')
|
||||||
|
msg = email.message_from_bytes(data[0][1])
|
||||||
|
|
||||||
|
for payload in msg.get_payload():
|
||||||
|
if (
|
||||||
|
payload.get_content_maintype() == 'text' and
|
||||||
|
payload.get_content_subtype() == 'plain'
|
||||||
|
):
|
||||||
|
plaintext_lines = payload.get_payload(decode=True).decode().splitlines()
|
||||||
|
code = plaintext_lines[plaintext_lines.index('Login Code') + 1]
|
||||||
|
break
|
||||||
|
|
||||||
|
print('code found:', code)
|
||||||
|
user.login(email_code=code, language='english')
|
||||||
|
|
||||||
|
with open('oauth_token', 'w') as file:
|
||||||
|
file.write(user.oauth_token)
|
||||||
|
|
||||||
|
print('password login successful')
|
||||||
|
|
||||||
# CRAWL
|
# CRAWL
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue