Add two factor authentication for boursorama module

This commit is contained in:
Gabriel 2012-12-05 18:11:22 +01:00 committed by Romain Bignon
commit ee4f3793a1
4 changed files with 196 additions and 9 deletions

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2012 Gabriel Serme
# Copyright(C) 2011 Gabriel Kerneis
# Copyright(C) 2010-2011 Jocelyn Jaubert
#
@ -20,25 +21,33 @@
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
from .pages import LoginPage, AccountsList, AccountHistory, UpdateInfoPage
from .pages import LoginPage, AccountsList, AccountHistory, UpdateInfoPage, AuthenticationPage
__all__ = ['Boursorama']
class BrowserIncorrectAuthenticationCode(BrowserIncorrectPassword):
pass
class Boursorama(BaseBrowser):
DOMAIN = 'www.boursorama.com'
PROTOCOL = 'https'
CERTHASH = '74429081f489cb723a82171a94350913d42727053fc86cf5bf5c3d65d39ec449'
ENCODING = None # refer to the HTML encoding
PAGES = {
'.*connexion.phtml.*': LoginPage,
'.*/comptes/synthese.phtml': AccountsList,
'.*/mouvements.phtml.*': AccountHistory,
'.*/connexion/securisation/index.phtml': AuthenticationPage,
'.*connexion.phtml.*': LoginPage,
'.*/comptes/synthese.phtml': AccountsList,
'.*/comptes/banque/detail/mouvements.phtml.*': AccountHistory,
'.*/date_anniversaire.phtml.*': UpdateInfoPage,
}
def __init__(self, *args, **kwargs):
def __init__(self, device="weboob", enable_twofactors=False
, *args, **kwargs):
self.device = device
self.enable_twofactors = enable_twofactors
BaseBrowser.__init__(self, *args, **kwargs)
def home(self):
@ -47,11 +56,25 @@ class Boursorama(BaseBrowser):
def is_logged(self):
return not self.is_on_page(LoginPage)
def handle_authentication(self):
if self.is_on_page(AuthenticationPage):
if self.enable_twofactors:
self.page.authenticate(self.device)
else:
print \
"""Boursorama - activate the two factor authentication in boursorama config."""\
""" You will receive SMS code but are limited in request per day (around 15)"""
def login(self):
assert isinstance(self.username, basestring)
assert isinstance(self.password, basestring)
assert isinstance(self.device, basestring)
assert isinstance(self.enable_twofactors, bool)
assert self.password.isdigit()
#for debug, save requested pages to tmp dir
#self.SAVE_RESPONSES = True
if not self.is_on_page(LoginPage):
self.location('https://' + self.DOMAIN + '/connexion.phtml')
@ -60,6 +83,22 @@ class Boursorama(BaseBrowser):
if self.is_on_page(LoginPage):
raise BrowserIncorrectPassword()
#after login, we might be redirected to the two factor
#authentication page
#print "handle authentication"
self.handle_authentication()
self.location('/comptes/synthese.phtml', no_login=True)
#if the login was correct but authentication code failed,
#we need to verify if bourso redirect us to login page or authentication page
if self.is_on_page(LoginPage):
#print "not correct after handling authentication"
raise BrowserIncorrectAuthenticationCode()
#print "login over"
def get_accounts_list(self):
if not self.is_on_page(AccountsList):
self.location('/comptes/synthese.phtml')