oauth
This commit is contained in:
		
							parent
							
								
									9107e00bb2
								
							
						
					
					
						commit
						dd7f82ee0b
					
				
					 1 changed files with 68 additions and 52 deletions
				
			
		
							
								
								
									
										54
									
								
								app.py
									
									
									
									
									
								
							
							
						
						
									
										54
									
								
								app.py
									
									
									
									
									
								
							|  | @ -9,37 +9,48 @@ 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: | ||||||
|  |     print('trying oauth login') | ||||||
|  |      | ||||||
|  |     with open('oauth_token', 'r') as file: | ||||||
|  |         user.oauth_login(file.read(), steam_id=environ['STEAM_ID'], language='english') | ||||||
|  |      | ||||||
|  |     print('oauth login successful') | ||||||
|  | except (wa.LoginIncorrect, FileNotFoundError) as exp: | ||||||
|  |     print('oauth login failed:', exp) | ||||||
|  |      | ||||||
|  |     # 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 | ||||||
|  | 
 | ||||||
|  |     try: | ||||||
|         user.login(environ['STEAM_PASSWORD']) |         user.login(environ['STEAM_PASSWORD']) | ||||||
| except (wa.LoginIncorrect) as exp: |     except (wa.LoginIncorrect) as exp: | ||||||
|         print('ERROR: loggin incorrect') |         print('ERROR: loggin incorrect') | ||||||
|         raise |         raise | ||||||
| except (wa.CaptchaRequired) as exp: |     except (wa.CaptchaRequired) as exp: | ||||||
|         print('ERROR: captcha required:', user.captcha_url) |         print('ERROR: captcha required:', user.captcha_url) | ||||||
|         #user.login(password=environ['STEAM_PASSWORD'], captcha=input("Captcha: ")) |         #user.login(password=environ['STEAM_PASSWORD'], captcha=input("Captcha: ")) | ||||||
|         raise |         raise | ||||||
| except wa.TwoFactorCodeRequired: |     except wa.TwoFactorCodeRequired: | ||||||
|         print('ERROR: 2FA code required') |         print('ERROR: 2FA code required') | ||||||
|         #user.login(twofactor_code=input("2FA Code: ")) |         #user.login(twofactor_code=input("2FA Code: ")) | ||||||
|         raise |         raise | ||||||
| except wa.EmailCodeRequired: |     except wa.EmailCodeRequired: | ||||||
|         print('getting email code') |         print('getting email code') | ||||||
|         while True: |         while True: | ||||||
|             typ, data = Mailbox.search(None, '(FROM "noreply@steampowered.com" SUBJECT "Your Steam account: Access from new web or mobile device")') |             typ, data = Mailbox.search(None, '(FROM "noreply@steampowered.com" SUBJECT "Your Steam account: Access from new web or mobile device")') | ||||||
|  | @ -65,7 +76,12 @@ except wa.EmailCodeRequired: | ||||||
|                 break |                 break | ||||||
|          |          | ||||||
|         print('code found:', code) |         print('code found:', code) | ||||||
|     user.login(email_code=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
	
	 mwiegand
						mwiegand