Commit 9882453c authored by ale's avatar ale

only ask for OTP if stdin is a tty

parent 49095906
import cookielib import cookielib
import getpass import getpass
import os
import urllib2 import urllib2
import urllib import urllib
import re import re
import sys
class SSOProcessor(urllib2.BaseHandler): class SSOProcessor(urllib2.BaseHandler):
...@@ -40,8 +42,11 @@ class SSOProcessor(urllib2.BaseHandler): ...@@ -40,8 +42,11 @@ class SSOProcessor(urllib2.BaseHandler):
self._username, form_data['s'].rstrip('/'))) self._username, form_data['s'].rstrip('/')))
form_data['password'] = self._password form_data['password'] = self._password
if self._otp_pattern.search(response_data): if self._otp_pattern.search(response_data):
form_data['otp'] = raw_input('OTP for %s@%s: ' % ( # Only ask for an OTP when the standard input is a tty,
self._username, form_data['s'].rstrip('/'))) # otherwise simply don't send any OTP.
if os.isatty(sys.stdin):
form_data['otp'] = raw_input('OTP for %s@%s: ' % (
self._username, form_data['s'].rstrip('/')))
newreq = urllib2.Request(request_baseurl, newreq = urllib2.Request(request_baseurl,
data=urllib.urlencode(form_data)) data=urllib.urlencode(form_data))
newreq.sso_attempt = True 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