mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-07 13:41:15 -07:00
Force refresh Plex.tv token in settings
* Removes the old PlexPy device and fetches a new token
This commit is contained in:
parent
73ac4076ac
commit
0b10e68c60
5 changed files with 115 additions and 20 deletions
|
@ -65,8 +65,8 @@ function confirmAjaxCall(url, msg, loader_msg, callback) {
|
|||
url: url,
|
||||
type: 'POST',
|
||||
complete: function (xhr, status) {
|
||||
result = $.parseJSON(xhr.responseText);
|
||||
msg = result.message;
|
||||
var result = $.parseJSON(xhr.responseText);
|
||||
var msg = result.message;
|
||||
if (result.result == 'success') {
|
||||
showMsg('<i class="fa fa-check"></i> ' + msg, false, true, 5000)
|
||||
} else {
|
||||
|
|
|
@ -1547,11 +1547,11 @@
|
|||
<div class="modal-body" id="modal-text">
|
||||
<div>
|
||||
<p class="help-block">
|
||||
This will attempt to fetch your token for you. This will not work on Internet Explorer 9 or lower.
|
||||
PlexPy does not store your username and password.
|
||||
This will attempt to fetch a new Plex.tv token for you. PlexPy does not store your username and password.
|
||||
Note: This will not work on Internet Explorer 9 or lower.
|
||||
</p>
|
||||
<div class="form-group">
|
||||
<label for="pms_username">PMS Username</label>
|
||||
<label for="pms_username">Plex.tv Username</label>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<input type="text" class="form-control" id="pms_username" name="pms_username" size="30">
|
||||
|
@ -1560,7 +1560,7 @@
|
|||
<p class="help-block">Username for Plex.tv authentication.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="pms_password">PMS Password</label>
|
||||
<label for="pms_password">Plex.tv Password</label>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<input type="password" class="form-control" id="pms_password" name="pms_password" size="30">
|
||||
|
@ -2388,21 +2388,24 @@ $(document).ready(function() {
|
|||
if ((pms_username !== '') && (pms_password !== '')) {
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: 'get_pms_token',
|
||||
url: 'get_plexpy_pms_token',
|
||||
data: {
|
||||
username: pms_username,
|
||||
password: pms_password
|
||||
password: pms_password,
|
||||
force: true
|
||||
},
|
||||
cache: false,
|
||||
async: true,
|
||||
complete: function(xhr, status) {
|
||||
var authToken = $.parseJSON(xhr.responseText);
|
||||
if (authToken) {
|
||||
$("#pms-token-status").html('<i class="fa fa-check"></i> Authentication successful!');
|
||||
var result = $.parseJSON(xhr.responseText);
|
||||
var msg = result.message;
|
||||
if (result.result == 'success') {
|
||||
var authToken = result.token;
|
||||
$("#pms-token-status").html('<i class="fa fa-check"></i> ' + msg);
|
||||
$("#pms_token").val(authToken);
|
||||
$('#pms-auth-modal').modal('hide');
|
||||
} else {
|
||||
$("#pms-token-status").html('<i class="fa fa-exclamation-circle"></i> Invalid username or password.');
|
||||
$("#pms-token-status").html('<i class="fa fa-exclamation-circle"></i> ' + msg);
|
||||
}
|
||||
loadUpdateDistros();
|
||||
}
|
||||
|
|
|
@ -418,7 +418,7 @@
|
|||
if ((pms_username !== '') && (pms_password !== '')) {
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: 'get_pms_token',
|
||||
url: 'get_plexpy_pms_token',
|
||||
data: {
|
||||
username: pms_username,
|
||||
password: pms_password
|
||||
|
@ -426,15 +426,17 @@
|
|||
cache: false,
|
||||
async: true,
|
||||
complete: function (xhr, status) {
|
||||
var authToken = $.parseJSON(xhr.responseText);
|
||||
if (authToken) {
|
||||
$("#pms-token-status").html('<i class="fa fa-check"></i> Authentication successful!');
|
||||
var result = $.parseJSON(xhr.responseText);
|
||||
var msg = result.message;
|
||||
if (result.result == 'success') {
|
||||
var authToken = result.token;
|
||||
$("#pms-token-status").html('<i class="fa fa-check"></i> ' + msg);
|
||||
$('#pms-token-status').fadeIn('fast');
|
||||
$("#pms_token").val(authToken);
|
||||
authenticated = true;
|
||||
getServerOptions(authToken)
|
||||
} else {
|
||||
$("#pms-token-status").html('<i class="fa fa-exclamation-circle"></i> Invalid username or password.');
|
||||
$("#pms-token-status").html('<i class="fa fa-exclamation-circle"></i> ' + msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -208,6 +208,32 @@ class PlexTV(object):
|
|||
else:
|
||||
return None
|
||||
|
||||
def get_plexpy_pms_token(self, force=False):
|
||||
if force:
|
||||
logger.debug(u"PlexPy PlexTV :: Forcing refresh of Plex.tv token.")
|
||||
devices_list = self.get_devices_list()
|
||||
device_id = next((d for d in devices_list if d['device_identifier'] == plexpy.CONFIG.PMS_UUID), {}).get('device_id', None)
|
||||
|
||||
if device_id:
|
||||
logger.debug(u"PlexPy PlexTV :: Removing PlexPy from Plex.tv devices.")
|
||||
try:
|
||||
self.delete_plextv_device(device_id=device_id)
|
||||
except:
|
||||
logger.error(u"PlexPy PlexTV :: Failed to remove PlexPy from Plex.tv devices.")
|
||||
return None
|
||||
else:
|
||||
logger.warn(u"PlexPy PlexTV :: No existing PlexPy device found.")
|
||||
|
||||
logger.info(u"PlexPy PlexTV :: Fetching a new Plex.tv token for PlexPy.")
|
||||
user = self.get_token()
|
||||
if user:
|
||||
token = user['auth_token']
|
||||
plexpy.CONFIG.__setattr__('PMS_TOKEN', token)
|
||||
plexpy.CONFIG.write()
|
||||
logger.info(u"PlexPy PlexTV :: Updated Plex.tv token for PlexPy.")
|
||||
return token
|
||||
|
||||
|
||||
def get_server_token(self):
|
||||
servers = self.get_plextv_server_list(output_format='xml')
|
||||
server_token = ''
|
||||
|
@ -251,6 +277,15 @@ class PlexTV(object):
|
|||
|
||||
return request
|
||||
|
||||
def get_plextv_devices_list(self, output_format=''):
|
||||
uri = '/devices.xml'
|
||||
request = self.request_handler.make_request(uri=uri,
|
||||
proto=self.protocol,
|
||||
request_type='GET',
|
||||
output_format=output_format)
|
||||
|
||||
return request
|
||||
|
||||
def get_plextv_server_list(self, output_format=''):
|
||||
uri = '/pms/servers.xml'
|
||||
request = self.request_handler.make_request(uri=uri,
|
||||
|
@ -293,6 +328,15 @@ class PlexTV(object):
|
|||
|
||||
return request
|
||||
|
||||
def delete_plextv_device(self, device_id='', output_format=''):
|
||||
uri = '/devices/%s.xml' % device_id
|
||||
request = self.request_handler.make_request(uri=uri,
|
||||
proto=self.protocol,
|
||||
request_type='DELETE',
|
||||
output_format=output_format)
|
||||
|
||||
return request
|
||||
|
||||
def get_full_users_list(self):
|
||||
friends_list = self.get_plextv_friends()
|
||||
own_account = self.get_plextv_user_details()
|
||||
|
@ -686,4 +730,32 @@ class PlexTV(object):
|
|||
logger.debug(u"PlexPy PlexTV :: Plex Pass subscription not found.")
|
||||
plexpy.CONFIG.__setattr__('PMS_PLEXPASS', 0)
|
||||
plexpy.CONFIG.write()
|
||||
return False
|
||||
return False return False
|
||||
|
||||
def get_devices_list(self):
|
||||
devices = self.get_plextv_devices_list(output_format='xml')
|
||||
|
||||
try:
|
||||
xml_head = devices.getElementsByTagName('Device')
|
||||
except Exception as e:
|
||||
logger.warn(u"PlexPy PlexTV :: Unable to parse XML for get_devices_list: %s." % e)
|
||||
return []
|
||||
|
||||
devices_list = []
|
||||
for a in xml_head:
|
||||
device = {"device_name": helpers.get_xml_attr(a, 'name'),
|
||||
"product": helpers.get_xml_attr(a, 'product'),
|
||||
"product_version": helpers.get_xml_attr(a, 'productVersion'),
|
||||
"platform": helpers.get_xml_attr(a, 'platform'),
|
||||
"platform_version": helpers.get_xml_attr(a, 'platformVersion'),
|
||||
"device": helpers.get_xml_attr(a, 'device'),
|
||||
"model": helpers.get_xml_attr(a, 'model'),
|
||||
"vendor": helpers.get_xml_attr(a, 'vendor'),
|
||||
"provides": helpers.get_xml_attr(a, 'provides'),
|
||||
"device_identifier": helpers.get_xml_attr(a, 'clientIdentifier'),
|
||||
"device_id": helpers.get_xml_attr(a, 'id'),
|
||||
"token": helpers.get_xml_attr(a, 'token')
|
||||
}
|
||||
devices_list.append(device)
|
||||
|
||||
return devices_list
|
||||
|
|
|
@ -3086,8 +3086,8 @@ class WebInterface(object):
|
|||
if not username and not password:
|
||||
return None
|
||||
|
||||
token = plextv.PlexTV(username=username, password=password)
|
||||
result = token.get_token()
|
||||
plex_tv = plextv.PlexTV(username=username, password=password)
|
||||
result = plex_tv.get_token()
|
||||
|
||||
if result:
|
||||
return result['auth_token']
|
||||
|
@ -3095,6 +3095,24 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve Plex.tv token.")
|
||||
return None
|
||||
|
||||
@cherrypy.expose
|
||||
@cherrypy.tools.json_out()
|
||||
@requireAuth(member_of("admin"))
|
||||
def get_plexpy_pms_token(self, username=None, password=None, force=False, **kwargs):
|
||||
""" Fetch a new Plex.tv token for PlexPy """
|
||||
if not username and not password:
|
||||
return None
|
||||
|
||||
force = True if force == 'true' else False
|
||||
|
||||
plex_tv = plextv.PlexTV(username=username, password=password)
|
||||
token = plex_tv.get_plexpy_pms_token(force=force)
|
||||
|
||||
if token:
|
||||
return {'result': 'success', 'message': 'Authentication successful.', 'token': token}
|
||||
else:
|
||||
return {'result': 'error', 'message': 'Authentication failed.'}
|
||||
|
||||
@cherrypy.expose
|
||||
@cherrypy.tools.json_out()
|
||||
@requireAuth(member_of("admin"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue