mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-11 09:06:58 -07:00
Pass OAuth client headers to server
This commit is contained in:
parent
24458bd23c
commit
2711597ffb
4 changed files with 41 additions and 34 deletions
|
@ -95,6 +95,10 @@
|
|||
<script src="${http_root}js/jquery-2.1.4.min.js"></script>
|
||||
<script src="${http_root}js/platform.min.js"></script>
|
||||
<script>
|
||||
if (!localStorage.getItem('Tautulli_ClientId')) {
|
||||
localStorage.setItem('Tautulli_ClientId', uuidv4());
|
||||
}
|
||||
|
||||
function uuidv4() {
|
||||
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
|
||||
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
||||
|
@ -105,7 +109,7 @@
|
|||
'Accept': 'application/json',
|
||||
'X-Plex-Product': '${plexpy.common.PRODUCT}',
|
||||
'X-Plex-Version': '${plexpy.common.RELEASE}',
|
||||
'X-Plex-Client-Identifier': uuidv4(),
|
||||
'X-Plex-Client-Identifier': localStorage.getItem('Tautulli_ClientId'),
|
||||
'X-Plex-Platform': platform.name,
|
||||
'X-Plex-Platform-Version': platform.version,
|
||||
'X-Plex-Device': platform.os.toString(),
|
||||
|
@ -189,15 +193,18 @@
|
|||
const password = plex ? null : $('#password').val();
|
||||
const remember_me = $('#remember_me').is(':checked') ? '1' : '0';
|
||||
|
||||
var data = {
|
||||
username: username,
|
||||
password: password,
|
||||
token: token,
|
||||
remember_me: remember_me
|
||||
};
|
||||
data = $.extend(data, x_plex_headers);
|
||||
|
||||
$.ajax({
|
||||
url: '${http_root}auth/signin',
|
||||
type: 'POST',
|
||||
data: {
|
||||
username: username,
|
||||
password: password,
|
||||
token: token,
|
||||
remember_me: remember_me
|
||||
},
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
statusCode: {
|
||||
200: function() {
|
||||
|
|
|
@ -33,20 +33,24 @@ class HTTPHandler(object):
|
|||
Retrieve data from Plex Server
|
||||
"""
|
||||
|
||||
def __init__(self, urls, token=None, timeout=10, ssl_verify=True):
|
||||
def __init__(self, urls, headers=None, token=None, timeout=10, ssl_verify=True):
|
||||
if isinstance(urls, basestring):
|
||||
self.urls = urls.split() or urls.split(',')
|
||||
else:
|
||||
self.urls = urls
|
||||
|
||||
self.headers = {'X-Plex-Product': plexpy.common.PRODUCT,
|
||||
'X-Plex-Version': plexpy.common.RELEASE,
|
||||
'X-Plex-Client-Identifier': plexpy.CONFIG.PMS_UUID,
|
||||
'X-Plex-Platform': plexpy.common.PLATFORM,
|
||||
'X-Plex-Platform-Version': plexpy.common.PLATFORM_RELEASE,
|
||||
'X-Plex-Device': 'Web',
|
||||
'X-Plex-Device-Name': plexpy.common.PLATFORM_DEVICE_NAME
|
||||
}
|
||||
if headers:
|
||||
self.headers = headers
|
||||
else:
|
||||
self.headers = {'X-Plex-Product': plexpy.common.PRODUCT,
|
||||
'X-Plex-Version': plexpy.common.RELEASE,
|
||||
'X-Plex-Client-Identifier': plexpy.CONFIG.PMS_UUID,
|
||||
'X-Plex-Platform': plexpy.common.PLATFORM,
|
||||
'X-Plex-Platform-Version': plexpy.common.PLATFORM_RELEASE,
|
||||
'X-Plex-Device': '{} {}'.format(plexpy.common.PLATFORM,
|
||||
plexpy.common.PLATFORM_RELEASE),
|
||||
'X-Plex-Device-Name': plexpy.common.PLATFORM_DEVICE_NAME
|
||||
}
|
||||
|
||||
self.token = token
|
||||
if self.token:
|
||||
|
|
|
@ -121,7 +121,7 @@ class PlexTV(object):
|
|||
Plex.tv authentication
|
||||
"""
|
||||
|
||||
def __init__(self, username=None, password=None, token=None):
|
||||
def __init__(self, username=None, password=None, token=None, headers=None):
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.token = token
|
||||
|
@ -147,7 +147,8 @@ class PlexTV(object):
|
|||
self.request_handler = http_handler.HTTPHandler(urls=self.urls,
|
||||
token=self.token,
|
||||
timeout=self.timeout,
|
||||
ssl_verify=self.ssl_verify)
|
||||
ssl_verify=self.ssl_verify,
|
||||
headers=headers)
|
||||
|
||||
def get_plex_auth(self, output_format='raw'):
|
||||
uri = '/users/sign_in.xml'
|
||||
|
|
|
@ -36,19 +36,19 @@ JWT_ALGORITHM = 'HS256'
|
|||
JWT_COOKIE_NAME = 'tautulli_token_'
|
||||
|
||||
|
||||
def user_login(username=None, password=None, token=None):
|
||||
def plex_user_login(username=None, password=None, token=None, headers=None):
|
||||
user_token = None
|
||||
user_id = None
|
||||
|
||||
# Try to login to Plex.tv to check if the user has a vaild account
|
||||
if username and password:
|
||||
plex_tv = PlexTV(username=username, password=password)
|
||||
plex_tv = PlexTV(username=username, password=password, headers=headers)
|
||||
plex_user = plex_tv.get_token()
|
||||
if plex_user:
|
||||
user_token = plex_user['auth_token']
|
||||
user_id = plex_user['user_id']
|
||||
elif token:
|
||||
plex_tv = PlexTV(token=token)
|
||||
plex_tv = PlexTV(token=token, headers=headers)
|
||||
plex_user = plex_tv.get_plex_account_details()
|
||||
if plex_user:
|
||||
user_token = token
|
||||
|
@ -77,7 +77,7 @@ def user_login(username=None, password=None, token=None):
|
|||
|
||||
# The user is in the database, and guest access is enabled, so try to retrieve a server token.
|
||||
# If a server token is returned, then the user is a valid friend of the server.
|
||||
plex_tv = PlexTV(token=user_token)
|
||||
plex_tv = PlexTV(token=user_token, headers=headers)
|
||||
server_token = plex_tv.get_server_token()
|
||||
if server_token:
|
||||
|
||||
|
@ -115,7 +115,7 @@ def user_login(username=None, password=None, token=None):
|
|||
return None
|
||||
|
||||
|
||||
def check_credentials(username=None, password=None, token=None, admin_login='0'):
|
||||
def check_credentials(username=None, password=None, token=None, admin_login='0', headers=None):
|
||||
"""Verifies credentials for username and password.
|
||||
Returns True and the user group on success or False and no user group"""
|
||||
|
||||
|
@ -130,16 +130,10 @@ def check_credentials(username=None, password=None, token=None, admin_login='0')
|
|||
username == plexpy.CONFIG.HTTP_USERNAME and password == plexpy.CONFIG.HTTP_PASSWORD:
|
||||
return True, user_details, 'admin'
|
||||
|
||||
if plexpy.CONFIG.HTTP_PLEX_ADMIN or (not admin_login == '1' and plexpy.CONFIG.ALLOW_GUEST_ACCESS):
|
||||
plex_login = user_login(username=username, password=password)
|
||||
if plex_login is not None:
|
||||
return True, plex_login[0], plex_login[1]
|
||||
|
||||
elif token:
|
||||
if plexpy.CONFIG.HTTP_PLEX_ADMIN or (not admin_login == '1' and plexpy.CONFIG.ALLOW_GUEST_ACCESS):
|
||||
plex_login = user_login(token=token)
|
||||
if plex_login is not None:
|
||||
return True, plex_login[0], plex_login[1]
|
||||
if plexpy.CONFIG.HTTP_PLEX_ADMIN or (not admin_login == '1' and plexpy.CONFIG.ALLOW_GUEST_ACCESS):
|
||||
plex_login = plex_user_login(username=username, password=password, token=token, headers=headers)
|
||||
if plex_login is not None:
|
||||
return True, plex_login[0], plex_login[1]
|
||||
|
||||
return False, None, None
|
||||
|
||||
|
@ -315,7 +309,8 @@ class AuthController(object):
|
|||
valid_login, user_details, user_group = check_credentials(username=username,
|
||||
password=password,
|
||||
token=token,
|
||||
admin_login=admin_login)
|
||||
admin_login=admin_login,
|
||||
headers=kwargs)
|
||||
|
||||
if valid_login:
|
||||
time_delta = timedelta(days=30) if remember_me == '1' else timedelta(minutes=60)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue