From 349984387888313cf5f245770e1a5010a770aede Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Sun, 26 Apr 2020 19:44:31 +0100 Subject: [PATCH] Added re-authentication after expiry to jf_api --- jellyfin_accounts/jf_api.py | 18 ++++++++++++++---- jellyfin_accounts/login.py | 5 ++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/jellyfin_accounts/jf_api.py b/jellyfin_accounts/jf_api.py index 8345aa7..ad0b5e5 100644 --- a/jellyfin_accounts/jf_api.py +++ b/jellyfin_accounts/jf_api.py @@ -36,9 +36,9 @@ class Jellyfin: "X-Emby-Authorization": self.auth } def getUsers(self, username="all", id="all", public=True): - if public: + if public is True: response = requests.get(self.server+"/emby/Users/Public").json() - else: + elif public is False and hasattr(self, 'username') and hasattr(self, 'password'): response = requests.get(self.server+"/emby/Users", headers=self.header, params={'Username': self.username, @@ -46,7 +46,13 @@ class Jellyfin: if response.status_code == 200: response = response.json() else: - raise self.AuthenticationRequiredError + try: + self.authenticate(self.username, self.password) + return self.getUsers(username, id, public) + except self.AuthenticationError: + raise self.AuthenticationRequiredError + else: + raise self.AuthenticationRequiredError if username == "all" and id == "all": return response elif id == "all": @@ -99,7 +105,11 @@ class Jellyfin: params={'Name': username, 'Password': password}) if response.status_code == 401: - raise self.AuthenticationRequiredError + if hasattr(self, 'username') and hasattr(self, 'password'): + self.authenticate(self.username, self.password) + return self.newUser(username, password) + else: + raise self.AuthenticationRequiredError return response # template user's policies should be copied to each new account. diff --git a/jellyfin_accounts/login.py b/jellyfin_accounts/login.py index e17a3e0..6be5d20 100644 --- a/jellyfin_accounts/login.py +++ b/jellyfin_accounts/login.py @@ -68,7 +68,10 @@ auth = HTTPBasicAuth() accounts = {} -if not config.getboolean('ui', 'jellyfin_login'): +if config.getboolean('ui', 'jellyfin_login'): + log.debug('Using jellyfin for admin authentication') +else: + log.debug('Using configured login details for admin authentication') accounts['adminAccount'] = Account(config['ui']['username'], config['ui']['password'])