Flag update JWT UUID after restarting

This commit is contained in:
JonnyWong16 2019-08-24 21:13:39 -07:00
parent f21d505ab8
commit 7498617b74
4 changed files with 15 additions and 15 deletions

View file

@ -222,6 +222,12 @@ def initialize(config_file):
CONFIG.JWT_SECRET = generate_uuid() CONFIG.JWT_SECRET = generate_uuid()
CONFIG.write() 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 # Get the previous version from the file
version_lock_file = os.path.join(DATA_DIR, "version.lock") version_lock_file = os.path.join(DATA_DIR, "version.lock")
prev_version = None prev_version = None

View file

@ -625,6 +625,7 @@ _CONFIG_DEFINITIONS = {
'XBMC_ON_NEWDEVICE': (int, 'XBMC', 0), 'XBMC_ON_NEWDEVICE': (int, 'XBMC', 0),
'JWT_SECRET': (str, 'Advanced', ''), 'JWT_SECRET': (str, 'Advanced', ''),
'JWT_UUID': (str, 'Advanced', ''), 'JWT_UUID': (str, 'Advanced', ''),
'JWT_UPDATE_UUID': (bool_int, 'Advanced', 0),
'SYSTEM_ANALYTICS': (int, 'Advanced', 1), 'SYSTEM_ANALYTICS': (int, 'Advanced', 1),
'WIN_SYS_TRAY': (int, 'General', 1) 'WIN_SYS_TRAY': (int, 'General', 1)
} }

View file

@ -138,15 +138,8 @@ def check_credentials(username=None, password=None, token=None, admin_login='0',
return False, None, None 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(): 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) jwt_token = cherrypy.request.cookie.get(jwt_cookie)
if jwt_token: if jwt_token:
@ -292,7 +285,7 @@ class AuthController(object):
if payload: if payload:
self.on_logout(payload['user'], payload['user_group']) 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] = 'expire'
cherrypy.response.cookie[jwt_cookie]['expires'] = 0 cherrypy.response.cookie[jwt_cookie]['expires'] = 0
cherrypy.response.cookie[jwt_cookie]['path'] = '/' cherrypy.response.cookie[jwt_cookie]['path'] = '/'
@ -338,14 +331,14 @@ class AuthController(object):
success=True, success=True,
oauth=bool(token)) 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] = jwt_token
cherrypy.response.cookie[jwt_cookie]['expires'] = int(time_delta.total_seconds()) cherrypy.response.cookie[jwt_cookie]['expires'] = int(time_delta.total_seconds())
cherrypy.response.cookie[jwt_cookie]['path'] = '/' cherrypy.response.cookie[jwt_cookie]['path'] = '/'
cherrypy.request.login = payload cherrypy.request.login = payload
cherrypy.response.status = 200 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: elif admin_login == '1' and username:
self.on_login(username=username) self.on_login(username=username)

View file

@ -2856,15 +2856,15 @@ class WebInterface(object):
else: else:
kwargs['http_password'] = plexpy.CONFIG.HTTP_PASSWORD kwargs['http_password'] = plexpy.CONFIG.HTTP_PASSWORD
# Refresh JWT uuid to log out clients # Flag to refresh JWT uuid to log out clients
webauth.jwt_uuid(refresh=True) kwargs['jwt_update_uuid'] = True
elif kwargs['http_password'] and kwargs.get('http_hash_password'): elif kwargs['http_password'] and kwargs.get('http_hash_password'):
kwargs['http_password'] = make_hash(kwargs['http_password']) kwargs['http_password'] = make_hash(kwargs['http_password'])
kwargs['http_hashed_password'] = 1 kwargs['http_hashed_password'] = 1
# Refresh JWT uuid to log out clients # Flag to refresh JWT uuid to log out clients
webauth.jwt_uuid(refresh=True) kwargs['jwt_update_uuid'] = True
elif not kwargs.get('http_hash_password'): elif not kwargs.get('http_hash_password'):
kwargs['http_hashed_password'] = 0 kwargs['http_hashed_password'] = 0