Commit 0feef324 authored by Thibault Douge's avatar Thibault Douge Committed by hydrargyrum
Browse files

[infomaniak] handle SCA

parent 7fe77b03
......@@ -22,7 +22,9 @@
from __future__ import unicode_literals
from woob.browser import LoginBrowser, URL, need_login
from woob.exceptions import BrowserIncorrectPassword
from woob.browser.exceptions import ServerError
from woob.exceptions import BrowserIncorrectPassword, BrowserQuestion
from import Value
from .pages import LoginPage, SubscriptionsPage, DocumentsPage
......@@ -34,11 +36,35 @@ class InfomaniakBrowser(LoginBrowser):
profile = URL(r'/v3/api/proxypass/profile', SubscriptionsPage)
documents = URL(r'/v3/api/invoicing/(?P<subid>.*)/invoices', DocumentsPage)
def __init__(self, config, *args, **kwargs):
self.config = config
kwargs['username'] = self.config['login'].get()
kwargs['password'] = self.config['password'].get()
super(InfomaniakBrowser, self).__init__(*args, **kwargs)
def do_login(self):
self.login.go(data={'login': self.username, 'password': self.password})
if self.config['otp'].get():
'login': self.username,
'password': self.password,
'double_auth_code': self.config['otp'].get(),
self.login.go(data={'login': self.username, 'password': self.password})
except ServerError as e:
if e.response.status_code == 500:
page = LoginPage(self, e.response)
# first for the wrongpass, second for the otp failed
error_msgs = ["Invalid login or password", "The authentication code is incorrect"]
if page.get_error() in error_msgs:
raise BrowserIncorrectPassword(page.get_error())
if not
raise BrowserIncorrectPassword()
if and not self.config['otp'].get():
raise BrowserQuestion(Value('otp', label='Enter the OTP'))
def iter_subscription(self):
......@@ -28,7 +28,8 @@
from woob.capabilities.base import find_object
from import Module, BackendConfig
from import ValueBackendPassword
from import ValueBackendPassword, ValueTransient
from .browser import InfomaniakBrowser
......@@ -46,6 +47,7 @@ class InfomaniakModule(Module, CapDocument):
CONFIG = BackendConfig(
ValueBackendPassword('login', label='Email de connexion', masked=False),
ValueBackendPassword('password', label='Mot de passe'),
BROWSER = InfomaniakBrowser
......@@ -53,7 +55,7 @@ class InfomaniakModule(Module, CapDocument):
accepted_document_types = (DocumentTypes.BILL,)
def create_default_browser(self):
return self.create_browser(self.config['login'].get(), self.config['password'].get())
return self.create_browser(self.config)
def iter_subscription(self):
return self.browser.iter_subscription()
......@@ -35,8 +35,17 @@
class LoginPage(JsonPage):
def logged(self):
if self.doc['data'].get('need_double_auth'):
return False
return self.doc['result'] == 'success'
def has_otp(self):
return self.doc['data']['default_method']
def get_error(self):
return self.doc['error']['description']
class SubscriptionsPage(LoggedPage, JsonPage):
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