diff --git a/plexpy/__init__.py b/plexpy/__init__.py index d552ad9f..95e0cfd2 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -222,6 +222,12 @@ def initialize(config_file): CONFIG.JWT_SECRET = generate_uuid() CONFIG.write() + if CONFIG.JWT_UUID == '' or CONFIG.JWT_UPDATE_UUID: + logger.debug(u"Generating JWT UUID...") + CONFIG.JWT_UUID = generate_uuid() + CONFIG.JWT_UPDATE_UUID = False + CONFIG.write() + # Get the previous version from the file version_lock_file = os.path.join(DATA_DIR, "version.lock") prev_version = None diff --git a/plexpy/config.py b/plexpy/config.py index f44cdf7a..06018904 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -625,6 +625,7 @@ _CONFIG_DEFINITIONS = { 'XBMC_ON_NEWDEVICE': (int, 'XBMC', 0), 'JWT_SECRET': (str, 'Advanced', ''), 'JWT_UUID': (str, 'Advanced', ''), + 'JWT_UPDATE_UUID': (bool_int, 'Advanced', 0), 'SYSTEM_ANALYTICS': (int, 'Advanced', 1), 'WIN_SYS_TRAY': (int, 'General', 1) } diff --git a/plexpy/webauth.py b/plexpy/webauth.py index dba87a6d..9027228d 100644 --- a/plexpy/webauth.py +++ b/plexpy/webauth.py @@ -138,15 +138,8 @@ def check_credentials(username=None, password=None, token=None, admin_login='0', return False, None, None -def jwt_uuid(refresh=False): - if not plexpy.CONFIG.JWT_UUID or refresh: - plexpy.CONFIG.JWT_UUID = plexpy.generate_uuid() - plexpy.CONFIG.write() - return plexpy.CONFIG.JWT_UUID - - def check_jwt_token(): - jwt_cookie = JWT_COOKIE_NAME + jwt_uuid() + jwt_cookie = JWT_COOKIE_NAME + plexpy.CONFIG.JWT_UUID jwt_token = cherrypy.request.cookie.get(jwt_cookie) if jwt_token: @@ -292,7 +285,7 @@ class AuthController(object): if payload: self.on_logout(payload['user'], payload['user_group']) - jwt_cookie = JWT_COOKIE_NAME + jwt_uuid() + jwt_cookie = JWT_COOKIE_NAME + plexpy.CONFIG.JWT_UUID cherrypy.response.cookie[jwt_cookie] = 'expire' cherrypy.response.cookie[jwt_cookie]['expires'] = 0 cherrypy.response.cookie[jwt_cookie]['path'] = '/' @@ -338,14 +331,14 @@ class AuthController(object): success=True, oauth=bool(token)) - jwt_cookie = JWT_COOKIE_NAME + jwt_uuid() + jwt_cookie = JWT_COOKIE_NAME + plexpy.CONFIG.JWT_UUID cherrypy.response.cookie[jwt_cookie] = jwt_token cherrypy.response.cookie[jwt_cookie]['expires'] = int(time_delta.total_seconds()) cherrypy.response.cookie[jwt_cookie]['path'] = '/' cherrypy.request.login = payload cherrypy.response.status = 200 - return {'status': 'success', 'token': jwt_token.decode('utf-8'), 'uuid': jwt_uuid()} + return {'status': 'success', 'token': jwt_token.decode('utf-8'), 'uuid': plexpy.CONFIG.JWT_UUID} elif admin_login == '1' and username: self.on_login(username=username) diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 8702da80..3f3e529a 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -2856,15 +2856,15 @@ class WebInterface(object): else: kwargs['http_password'] = plexpy.CONFIG.HTTP_PASSWORD - # Refresh JWT uuid to log out clients - webauth.jwt_uuid(refresh=True) + # Flag to refresh JWT uuid to log out clients + kwargs['jwt_update_uuid'] = True elif kwargs['http_password'] and kwargs.get('http_hash_password'): kwargs['http_password'] = make_hash(kwargs['http_password']) kwargs['http_hashed_password'] = 1 - # Refresh JWT uuid to log out clients - webauth.jwt_uuid(refresh=True) + # Flag to refresh JWT uuid to log out clients + kwargs['jwt_update_uuid'] = True elif not kwargs.get('http_hash_password'): kwargs['http_hashed_password'] = 0