Commit 16c53ab8 authored by ale's avatar ale

detect OTP and ask the user for it

parent aaa63677
......@@ -11,6 +11,7 @@ class SSOProcessor(urllib2.BaseHandler):
LOGIN_SERVER = 'https://login.autistici.org/'
_form_pattern = re.compile(r'<input type="hidden" name="([^"]+)" value="([^"]+)"')
_otp_pattern = re.compile(r'<input[^>]+ name="otp"')
def __init__(self, username=None, password=None):
self._username = username or getpass.getuser()
......@@ -30,13 +31,17 @@ class SSOProcessor(urllib2.BaseHandler):
if (resp.code == 200 and request_url.startswith(self.LOGIN_SERVER)):
if not hasattr(req, 'sso_attempt'):
request_baseurl = request_url.split('?')[0]
form_data = self._extract_hidden_form_data(resp.read())
response_data = resp.read()
form_data = self._extract_hidden_form_data(response_data)
form_data['username'] = self._username
if not self._password:
self._password = getpass.getpass(
prompt='Password for %s@%s: ' % (
self._username, form_data['s'].rstrip('/')))
form_data['password'] = self._password
if self._otp_pattern.search(response_data):
form_data['otp'] = raw_input('OTP for %s@%s: ' % (
self._username, form_data['s'].rstrip('/')))
newreq = urllib2.Request(request_baseurl,
data=urllib.urlencode(form_data))
newreq.sso_attempt = True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment