def outlook_auth(email, password): provider_mod = sys.modules['inbox.auth.outlook'] session = requests.Session() url = authorize_link(provider_mod, email) req = session.get(url) assert req.ok auth_parser = OutlookAuthParser() auth_parser.feed(req.text) params = auth_parser.params params['login'] = email params['passwd'] = password req = session.post(auth_parser.action, data=params) assert req.ok update_parser = OutlookUpdateParser() update_parser.feed(req.text) req = session.post(update_parser.action, data=update_parser.params) assert req.ok consent_parser = OutlookConsentParser() consent_parser.feed(req.text) req = session.post(update_parser.action, data=consent_parser.params) assert req.ok code = re.match('https.*code=(.*)&lc=1033', req.url).group(1) return code
def google_auth(email, password): gmail_provider = sys.modules['inbox.auth.gmail'] session = requests.Session() url = authorize_link(gmail_provider, email) req = session.get(url) assert req.ok auth_parser = GoogleAuthParser() auth_parser.feed(req.text) params = auth_parser.params action = auth_parser.action params['Email'] = email params['Passwd'] = password req = session.post(action, data=params) assert req.ok connect_parser = GoogleConnectParser() connect_parser.feed(req.text) params = connect_parser.params action = connect_parser.action params['submit_access'] = 'true' req = session.post(action, data=params) assert req.ok token_parser = GoogleTokenParser() token_parser.feed(req.text) return token_parser.code