Skip to content

Commit

Permalink
browser: reuse cached authentication sessions
Browse files Browse the repository at this point in the history
With this change it is now possible for IDPs to persist cookies between
authentications. When properly configuired, IDPs may not even ask for a
password anymore.
  • Loading branch information
László Vaskó committed Mar 1, 2021
1 parent c39d32a commit 2f6614e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## vNext

- It is now possible to reuse previous authentication sessions, so that
entering password/MFA token may not be needed at all.

## v0.6.3

- Updating `poetry2nix` to fix build on `nixpkgs-unstable`
Expand Down
22 changes: 15 additions & 7 deletions openconnect_sso/browser/webengine_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import structlog

from PyQt5.QtCore import QUrl, QTimer
from PyQt5.QtNetwork import QNetworkProxy
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineScript
from PyQt5.QtNetwork import QNetworkCookie, QNetworkProxy
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineScript, QWebEngineProfile
from PyQt5.QtWidgets import QApplication

from openconnect_sso import config
Expand Down Expand Up @@ -119,6 +119,19 @@ async def wait(self):
self.join()


def on_sigterm(signum, frame):
logger.info("Terminate requested.")
# Force flush cookieStore to disk. Without this hack the cookieStore may
# not be synced at all if the browser lives only for a short amount of
# time. Something is off with the call order of destructors as there is no
# such issue in C++.

# See: https://github.com/qutebrowser/qutebrowser/commit/8d55d093f29008b268569cdec28b700a8c42d761
cookie = QNetworkCookie()
QWebEngineProfile.defaultProfile().cookieStore().deleteCookie(cookie)
QApplication.quit()


class WebBrowser(QWebEngineView):
def __init__(self, auto_fill_rules, on_update):
super().__init__()
Expand Down Expand Up @@ -199,8 +212,3 @@ def get_selectors(rules, credentials):
f"""var elem = document.querySelector({selector}); if (elem) {{ elem.dispatchEvent(new Event("focus")); elem.click(); }}"""
)
return "\n".join(statements)


def on_sigterm(signum, frame):
logger.info("SIGNAL handler")
QApplication.quit()

0 comments on commit 2f6614e

Please sign in to comment.