Commit 69636dcd authored by Cédric Bellegarde's avatar Cédric Bellegarde

Enable Two Factor Authentication. Fix #336

parent 1eb206b0
Pipeline #76231 passed with stage
in 10 minutes and 28 seconds
......@@ -926,7 +926,7 @@ on all your devices running Eolie or Firefox</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Login:</property>
<property name="label" translatable="yes">Login :</property>
</object>
<packing>
<property name="left_attach">0</property>
......@@ -948,7 +948,7 @@ on all your devices running Eolie or Firefox</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Password:</property>
<property name="label" translatable="yes">Password :</property>
</object>
<packing>
<property name="left_attach">0</property>
......@@ -981,7 +981,7 @@ on all your devices running Eolie or Firefox</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
......@@ -991,7 +991,7 @@ on all your devices running Eolie or Firefox</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
......@@ -1001,7 +1001,7 @@ on all your devices running Eolie or Firefox</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
......@@ -1020,6 +1020,30 @@ on all your devices running Eolie or Firefox</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Code :</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="code_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">You need to enable Two Factor Authentication</property>
<property name="placeholder_text" translatable="yes">You need to enable Two Factor Authentication</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<placeholder/>
</child>
......
......@@ -77,12 +77,12 @@ class SyncWorker:
self.__helper = PasswordsHelper()
self.set_credentials()
def login(self, attributes, password):
def login(self, attributes, password, code):
"""
Login to service
@param attributes as {}
@param password as str
@raise exceptions
@param code as str
"""
self.__username = ""
self.__password = ""
......@@ -98,7 +98,8 @@ class SyncWorker:
self.__password = password
# Connect to firefox sync
try:
session = self.__firefox_sync.login(self.__username, password)
session = self.__firefox_sync.login(
self.__username, password, code)
bid_assertion, key = self.__firefox_sync.\
get_browserid_assertion(session)
self.__token = session.token
......@@ -107,7 +108,7 @@ class SyncWorker:
keyB_encoded = b64encode(self.__keyB).decode("utf-8")
self.__helper.clear_sync(self.__helper.store_sync,
self.__username,
password,
"",
self.__uid,
self.__token,
keyB_encoded,
......@@ -552,8 +553,6 @@ class SyncWorker:
Logger.sync_debug("Stop syncing")
except Exception as e:
Logger.error("SyncWorker::__sync(): %s", e)
if str(e) == "The authentication token could not be found":
self.set_credentials()
self.__syncing = False
def __pull_bookmarks(self, bulk_keys):
......@@ -749,9 +748,6 @@ class SyncWorker:
self.__token = attributes["token"]
self.__uid = attributes["uid"]
self.__keyB = b64decode(attributes["keyB"])
# Force login if no token
if not self.__token:
self.login(attributes, password)
self.sync()
except Exception as e:
Logger.error("SyncWorker::__set_credentials(): %s" % e)
......@@ -782,14 +778,16 @@ class FirefoxSync(object):
from fxa.core import Client as FxAClient
self.__fxa_client = FxAClient()
def login(self, login, password):
def login(self, login, password, code):
"""
Login to FxA and get the keys.
@param login as str
@param password as str
@param code as str
@return fxaSession
"""
fxaSession = self.__fxa_client.login(login, password, keys=True)
fxaSession.totp_verify(code)
fxaSession.fetch_keys()
return fxaSession
......
......@@ -178,6 +178,7 @@ class SettingsDialog:
self.__sync_button = builder.get_object("sync_button")
self.__login_entry = builder.get_object("login_entry")
self.__password_entry = builder.get_object("password_entry")
self.__code_entry = builder.get_object("code_entry")
self.__result_image = builder.get_object("result_image")
builder.connect_signals(self)
self.__helper.get_sync(self.__on_get_sync)
......@@ -476,7 +477,8 @@ class SettingsDialog:
task_helper = TaskHelper()
task_helper.run(self.__connect_firefox_sync,
self.__login_entry.get_text(),
self.__password_entry.get_text())
self.__password_entry.get_text(),
self.__code_entry.get_text())
#######################
# PRIVATE #
......@@ -539,32 +541,25 @@ class SettingsDialog:
" on your computer:\n%s") % cmd)
self.__sync_button.set_sensitive(False)
def __connect_firefox_sync(self, username, password):
def __connect_firefox_sync(self, username, password, code):
"""
Connect to firefox sync
@param username as str
@param password as str
@param code as str
@thread safe
"""
try:
App().sync_worker.new_session()
App().sync_worker.login({"login": username}, password)
App().sync_worker.login({"login": username}, password, code)
GLib.idle_add(self.__setup_sync_button, True)
except Exception as e:
Logger.error("SettingsDialog::__connect_firefox_sync(): %s", e)
GLib.idle_add(self.__sync_button.set_sensitive, True)
if str(e) == "Unverified account":
GLib.timeout_add(500, self.__settings_dialog.destroy)
self.__window.toolbar.end.show_sync_button()
GLib.idle_add(
App().active_window.toolbar.title.show_message,
_("You've received an email"
" to validate syncing"))
else:
GLib.idle_add(self.__result_label.set_text, str(e))
GLib.idle_add(self.__result_image.set_from_icon_name,
"computer-fail-symbolic",
Gtk.IconSize.MENU)
GLib.idle_add(self.__result_label.set_text, str(e))
GLib.idle_add(self.__result_image.set_from_icon_name,
"computer-fail-symbolic",
Gtk.IconSize.MENU)
def __on_get_sync(self, attributes, password, uri, index, count):
"""
......
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