From 6ff20ca60515d311bbbb39eb34fa18d7a0248711 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Thu, 29 Feb 2024 21:59:23 +0100 Subject: [PATCH] Implement cookie authentication --- src/fime/util.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/fime/util.py b/src/fime/util.py index b579bd6..44f1980 100644 --- a/src/fime/util.py +++ b/src/fime/util.py @@ -1,9 +1,10 @@ import enum +import browser_cookie3 from loguru import logger from requests import Session -from fime.config import Config, AuthMethods +from fime.config import Config, AuthMethods, Browsers try: from PySide6 import QtCore, QtGui, QtWidgets @@ -61,6 +62,21 @@ def add_auth(config: Config, session: Session): case AuthMethods.TOKEN: session.headers["Authorization"] = f"Bearer {config.jira_token}" case AuthMethods.COOKIES: - raise NotImplemented + match config.cookie_source: + case Browsers.AUTO: + cookie_jar = browser_cookie3.load() + case Browsers.FIREFOX: + cookie_jar = browser_cookie3.firefox() + case Browsers.CHROME: + cookie_jar = browser_cookie3.chrome() + case Browsers.CHROMIUM: + cookie_jar = browser_cookie3.chromium() + case Browsers.EDGE: + cookie_jar = browser_cookie3.edge() + case Browsers.OPERA: + cookie_jar = browser_cookie3.opera() + case _: + raise AssertionError("Unknown cookie_source") + session.cookies = cookie_jar case _: raise AssertionError("Unknown auth method")