boursorama two_authentication with BrowserToBeContinued instead of raw_input

This commit is contained in:
Baptiste Delpey 2015-03-06 17:27:09 +01:00 committed by Romain Bignon
commit aa721c28b8
3 changed files with 75 additions and 83 deletions

View file

@ -17,23 +17,55 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.deprecated.browser import Page, BrowserIncorrectPassword
import urllib2
import re
import urllib2
from weboob.exceptions import BrowserToBeContinued
from weboob.deprecated.browser import Page, BrowserIncorrectPassword
class BrowserAuthenticationCodeMaxLimit(BrowserIncorrectPassword):
pass
class AuthenticationPage(Page):
MAX_LIMIT = "vous avez atteint le nombre maximum "\
MAX_LIMIT = r"vous avez atteint le nombre maximum "\
"d'utilisation de l'authentification forte."
SECURE_PAGE = "https://www.boursorama.com/comptes/connexion/securisation/index.phtml"
REFERER = SECURE_PAGE
headers = {"User-Agent": "Mozilla/5.0 (Windows; U; Windows "
"NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8"
" GTB7.1 (.NET CLR 3.5.30729)",
"Referer": REFERER,
}
headers_ajax = {"User-Agent": "Mozilla/5.0 (Windows; U; Windows "
"NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8"
" GTB7.1 (.NET CLR 3.5.30729)",
"Accept": "application/json",
"X-Requested-With": "XMLHttpRequest",
"X-Request": "JSON",
"X-Brs-Xhr-Request": "true",
"X-Brs-Xhr-Schema": "DATA+OUT",
"Referer": REFERER,
}
def on_loaded(self):
pass
def authenticate(self, device):
def authenticate(self):
url = "https://" + self.browser.DOMAIN + "/ajax/banque/otp.phtml"
data = "authentificationforteToken=%s&authentificationforteStep=otp&alertType=10100&org=%s&otp=%s&validate=" % (self.browser.auth_token, self.REFERER, self.browser.config['pin_code'].get())
req = urllib2.Request(url, data, self.headers_ajax)
response = self.browser.open(req)
url = "%s?" % (self.SECURE_PAGE)
data = "org=/&device=%s" % (self.browser.config['device'].get())
req = urllib2.Request(url, data, headers=self.headers)
response = self.browser.open(req)
self.browser.auth_token = None
def send_sms(self):
"""This function simulates the registration of a device on
boursorama two factor authentification web page.
I
@ -41,73 +73,26 @@ class AuthenticationPage(Page):
@exception BrowserAuthenticationCodeMaxLimit when daily limit is consumed
@exception BrowserIncorrectAuthenticationCode when code is not correct
"""
DOMAIN = self.browser.DOMAIN
SECURE_PAGE = "https://www.boursorama.com/comptes/connexion/securisation/index.phtml"
REFERER = SECURE_PAGE
#print "Need to authenticate for device", device
#print "Domain information", DOMAIN
url = "https://%s/ajax/banque/otp.phtml?org=%s&alertType=10100" % (DOMAIN, REFERER)
#print url
headers = {"User-Agent": "Mozilla/5.0 (Windows; U; Windows "
"NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8"
" GTB7.1 (.NET CLR 3.5.30729)",
"Referer": REFERER,
}
headers_ajax = {"User-Agent": "Mozilla/5.0 (Windows; U; Windows "
"NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8"
" GTB7.1 (.NET CLR 3.5.30729)",
"Accept": "application/json",
"X-Requested-With": "XMLHttpRequest",
"X-Request": "JSON",
"X-Brs-Xhr-Request": "true",
"X-Brs-Xhr-Schema": "DATA+OUT",
"Referer": REFERER,
}
req = urllib2.Request(url, headers=headers_ajax)
url = "https://%s/ajax/banque/otp.phtml?org=%s&alertType=10100" % (self.browser.DOMAIN, self.REFERER)
req = urllib2.Request(url, headers=self.headers_ajax)
response = self.browser.open(req)
#extrat authentication token from response (in form)
info = response.read()
regex = re.compile(r"vous avez atteint le nombre maximum d'utilisation de l'authentification forte.")
regex = re.compile(self.MAX_LIMIT)
r = regex.search(info)
if r:
self.logger.info("Boursorama - Vous avez atteint le nombre maximum d'utilisation de l'authentification forte")
raise BrowserAuthenticationCodeMaxLimit()
#print "Response from initial request,", len(info), response.info()
regex = re.compile(r"name=\\\"authentificationforteToken\\\" "
r"value=\\\"(?P<value>\w*?)\\\"")
r = regex.search(info)
token = r.group('value')
#print "Extracted token", token
self.browser.auth_token = r.group('value')
#step2
url = "https://" + DOMAIN + "/ajax/banque/otp.phtml"
data = "authentificationforteToken=%s&authentificationforteStep=start&alertType=10100&org=%s&validate=" % (token, REFERER)
req = urllib2.Request(url, data, headers_ajax)
url = "https://" + self.browser.DOMAIN + "/ajax/banque/otp.phtml"
data = "authentificationforteToken=%s&authentificationforteStep=start&alertType=10100&org=%s&validate=" % (self.browser.auth_token, self.REFERER)
req = urllib2.Request(url, data, self.headers_ajax)
response = self.browser.open(req)
#info = response.read()
#print "after asking to send token authentification" \
# ,len(info), response.info()
pin = raw_input('Enter the "Boursorama Banque" access code:')
#print "Pin access code: ''%s''" % (pin)
url = "https://" + DOMAIN + "/ajax/banque/otp.phtml"
data = "authentificationforteToken=%s&authentificationforteStep=otp&alertType=10100&org=%s&otp=%s&validate=" % (token, REFERER, pin)
req = urllib2.Request(url, data, headers_ajax)
response = self.browser.open(req)
#info = response.read()
#print "after pin authentification", len(info), response.info()
url = "%s?" % (SECURE_PAGE)
data = "org=/&device=%s" % (device)
req = urllib2.Request(url, data, headers=headers)
response = self.browser.open(req)
#result = response.read()
#print response, "\n", response.info()
raise BrowserToBeContinued('pin_code')