mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-06 21:21: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,
|
url: url,
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
complete: function (xhr, status) {
|
complete: function (xhr, status) {
|
||||||
result = $.parseJSON(xhr.responseText);
|
var result = $.parseJSON(xhr.responseText);
|
||||||
msg = result.message;
|
var msg = result.message;
|
||||||
if (result.result == 'success') {
|
if (result.result == 'success') {
|
||||||
showMsg('<i class="fa fa-check"></i> ' + msg, false, true, 5000)
|
showMsg('<i class="fa fa-check"></i> ' + msg, false, true, 5000)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1547,11 +1547,11 @@
|
||||||
<div class="modal-body" id="modal-text">
|
<div class="modal-body" id="modal-text">
|
||||||
<div>
|
<div>
|
||||||
<p class="help-block">
|
<p class="help-block">
|
||||||
This will attempt to fetch your token for you. This will not work on Internet Explorer 9 or lower.
|
This will attempt to fetch a new Plex.tv token for you. PlexPy does not store your username and password.
|
||||||
PlexPy does not store your username and password.
|
Note: This will not work on Internet Explorer 9 or lower.
|
||||||
</p>
|
</p>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="pms_username">PMS Username</label>
|
<label for="pms_username">Plex.tv Username</label>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<input type="text" class="form-control" id="pms_username" name="pms_username" size="30">
|
<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>
|
<p class="help-block">Username for Plex.tv authentication.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="pms_password">PMS Password</label>
|
<label for="pms_password">Plex.tv Password</label>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<input type="password" class="form-control" id="pms_password" name="pms_password" size="30">
|
<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 !== '')) {
|
if ((pms_username !== '') && (pms_password !== '')) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: 'get_pms_token',
|
url: 'get_plexpy_pms_token',
|
||||||
data: {
|
data: {
|
||||||
username: pms_username,
|
username: pms_username,
|
||||||
password: pms_password
|
password: pms_password,
|
||||||
|
force: true
|
||||||
},
|
},
|
||||||
cache: false,
|
cache: false,
|
||||||
async: true,
|
async: true,
|
||||||
complete: function(xhr, status) {
|
complete: function(xhr, status) {
|
||||||
var authToken = $.parseJSON(xhr.responseText);
|
var result = $.parseJSON(xhr.responseText);
|
||||||
if (authToken) {
|
var msg = result.message;
|
||||||
$("#pms-token-status").html('<i class="fa fa-check"></i> Authentication successful!');
|
if (result.result == 'success') {
|
||||||
|
var authToken = result.token;
|
||||||
|
$("#pms-token-status").html('<i class="fa fa-check"></i> ' + msg);
|
||||||
$("#pms_token").val(authToken);
|
$("#pms_token").val(authToken);
|
||||||
$('#pms-auth-modal').modal('hide');
|
$('#pms-auth-modal').modal('hide');
|
||||||
} else {
|
} 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();
|
loadUpdateDistros();
|
||||||
}
|
}
|
||||||
|
|
|
@ -418,7 +418,7 @@
|
||||||
if ((pms_username !== '') && (pms_password !== '')) {
|
if ((pms_username !== '') && (pms_password !== '')) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: 'get_pms_token',
|
url: 'get_plexpy_pms_token',
|
||||||
data: {
|
data: {
|
||||||
username: pms_username,
|
username: pms_username,
|
||||||
password: pms_password
|
password: pms_password
|
||||||
|
@ -426,15 +426,17 @@
|
||||||
cache: false,
|
cache: false,
|
||||||
async: true,
|
async: true,
|
||||||
complete: function (xhr, status) {
|
complete: function (xhr, status) {
|
||||||
var authToken = $.parseJSON(xhr.responseText);
|
var result = $.parseJSON(xhr.responseText);
|
||||||
if (authToken) {
|
var msg = result.message;
|
||||||
$("#pms-token-status").html('<i class="fa fa-check"></i> Authentication successful!');
|
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-status').fadeIn('fast');
|
||||||
$("#pms_token").val(authToken);
|
$("#pms_token").val(authToken);
|
||||||
authenticated = true;
|
authenticated = true;
|
||||||
getServerOptions(authToken)
|
getServerOptions(authToken)
|
||||||
} else {
|
} 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:
|
else:
|
||||||
return None
|
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):
|
def get_server_token(self):
|
||||||
servers = self.get_plextv_server_list(output_format='xml')
|
servers = self.get_plextv_server_list(output_format='xml')
|
||||||
server_token = ''
|
server_token = ''
|
||||||
|
@ -251,6 +277,15 @@ class PlexTV(object):
|
||||||
|
|
||||||
return request
|
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=''):
|
def get_plextv_server_list(self, output_format=''):
|
||||||
uri = '/pms/servers.xml'
|
uri = '/pms/servers.xml'
|
||||||
request = self.request_handler.make_request(uri=uri,
|
request = self.request_handler.make_request(uri=uri,
|
||||||
|
@ -293,6 +328,15 @@ class PlexTV(object):
|
||||||
|
|
||||||
return request
|
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):
|
def get_full_users_list(self):
|
||||||
friends_list = self.get_plextv_friends()
|
friends_list = self.get_plextv_friends()
|
||||||
own_account = self.get_plextv_user_details()
|
own_account = self.get_plextv_user_details()
|
||||||
|
@ -686,4 +730,32 @@ class PlexTV(object):
|
||||||
logger.debug(u"PlexPy PlexTV :: Plex Pass subscription not found.")
|
logger.debug(u"PlexPy PlexTV :: Plex Pass subscription not found.")
|
||||||
plexpy.CONFIG.__setattr__('PMS_PLEXPASS', 0)
|
plexpy.CONFIG.__setattr__('PMS_PLEXPASS', 0)
|
||||||
plexpy.CONFIG.write()
|
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:
|
if not username and not password:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
token = plextv.PlexTV(username=username, password=password)
|
plex_tv = plextv.PlexTV(username=username, password=password)
|
||||||
result = token.get_token()
|
result = plex_tv.get_token()
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
return result['auth_token']
|
return result['auth_token']
|
||||||
|
@ -3095,6 +3095,24 @@ class WebInterface(object):
|
||||||
logger.warn(u"Unable to retrieve Plex.tv token.")
|
logger.warn(u"Unable to retrieve Plex.tv token.")
|
||||||
return None
|
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.expose
|
||||||
@cherrypy.tools.json_out()
|
@cherrypy.tools.json_out()
|
||||||
@requireAuth(member_of("admin"))
|
@requireAuth(member_of("admin"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue