mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-19 12:59:42 -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/jquery-2.1.4.min.js"></script>
|
||||||
<script src="${http_root}js/platform.min.js"></script>
|
<script src="${http_root}js/platform.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
if (!localStorage.getItem('Tautulli_ClientId')) {
|
||||||
|
localStorage.setItem('Tautulli_ClientId', uuidv4());
|
||||||
|
}
|
||||||
|
|
||||||
function uuidv4() {
|
function uuidv4() {
|
||||||
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
|
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
|
||||||
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
||||||
|
@ -105,7 +109,7 @@
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'X-Plex-Product': '${plexpy.common.PRODUCT}',
|
'X-Plex-Product': '${plexpy.common.PRODUCT}',
|
||||||
'X-Plex-Version': '${plexpy.common.RELEASE}',
|
'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': platform.name,
|
||||||
'X-Plex-Platform-Version': platform.version,
|
'X-Plex-Platform-Version': platform.version,
|
||||||
'X-Plex-Device': platform.os.toString(),
|
'X-Plex-Device': platform.os.toString(),
|
||||||
|
@ -189,15 +193,18 @@
|
||||||
const password = plex ? null : $('#password').val();
|
const password = plex ? null : $('#password').val();
|
||||||
const remember_me = $('#remember_me').is(':checked') ? '1' : '0';
|
const remember_me = $('#remember_me').is(':checked') ? '1' : '0';
|
||||||
|
|
||||||
$.ajax({
|
var data = {
|
||||||
url: '${http_root}auth/signin',
|
|
||||||
type: 'POST',
|
|
||||||
data: {
|
|
||||||
username: username,
|
username: username,
|
||||||
password: password,
|
password: password,
|
||||||
token: token,
|
token: token,
|
||||||
remember_me: remember_me
|
remember_me: remember_me
|
||||||
},
|
};
|
||||||
|
data = $.extend(data, x_plex_headers);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '${http_root}auth/signin',
|
||||||
|
type: 'POST',
|
||||||
|
data: data,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
statusCode: {
|
statusCode: {
|
||||||
200: function() {
|
200: function() {
|
||||||
|
|
|
@ -33,18 +33,22 @@ class HTTPHandler(object):
|
||||||
Retrieve data from Plex Server
|
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):
|
if isinstance(urls, basestring):
|
||||||
self.urls = urls.split() or urls.split(',')
|
self.urls = urls.split() or urls.split(',')
|
||||||
else:
|
else:
|
||||||
self.urls = urls
|
self.urls = urls
|
||||||
|
|
||||||
|
if headers:
|
||||||
|
self.headers = headers
|
||||||
|
else:
|
||||||
self.headers = {'X-Plex-Product': plexpy.common.PRODUCT,
|
self.headers = {'X-Plex-Product': plexpy.common.PRODUCT,
|
||||||
'X-Plex-Version': plexpy.common.RELEASE,
|
'X-Plex-Version': plexpy.common.RELEASE,
|
||||||
'X-Plex-Client-Identifier': plexpy.CONFIG.PMS_UUID,
|
'X-Plex-Client-Identifier': plexpy.CONFIG.PMS_UUID,
|
||||||
'X-Plex-Platform': plexpy.common.PLATFORM,
|
'X-Plex-Platform': plexpy.common.PLATFORM,
|
||||||
'X-Plex-Platform-Version': plexpy.common.PLATFORM_RELEASE,
|
'X-Plex-Platform-Version': plexpy.common.PLATFORM_RELEASE,
|
||||||
'X-Plex-Device': 'Web',
|
'X-Plex-Device': '{} {}'.format(plexpy.common.PLATFORM,
|
||||||
|
plexpy.common.PLATFORM_RELEASE),
|
||||||
'X-Plex-Device-Name': plexpy.common.PLATFORM_DEVICE_NAME
|
'X-Plex-Device-Name': plexpy.common.PLATFORM_DEVICE_NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,7 @@ class PlexTV(object):
|
||||||
Plex.tv authentication
|
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.username = username
|
||||||
self.password = password
|
self.password = password
|
||||||
self.token = token
|
self.token = token
|
||||||
|
@ -147,7 +147,8 @@ class PlexTV(object):
|
||||||
self.request_handler = http_handler.HTTPHandler(urls=self.urls,
|
self.request_handler = http_handler.HTTPHandler(urls=self.urls,
|
||||||
token=self.token,
|
token=self.token,
|
||||||
timeout=self.timeout,
|
timeout=self.timeout,
|
||||||
ssl_verify=self.ssl_verify)
|
ssl_verify=self.ssl_verify,
|
||||||
|
headers=headers)
|
||||||
|
|
||||||
def get_plex_auth(self, output_format='raw'):
|
def get_plex_auth(self, output_format='raw'):
|
||||||
uri = '/users/sign_in.xml'
|
uri = '/users/sign_in.xml'
|
||||||
|
|
|
@ -36,19 +36,19 @@ JWT_ALGORITHM = 'HS256'
|
||||||
JWT_COOKIE_NAME = 'tautulli_token_'
|
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_token = None
|
||||||
user_id = None
|
user_id = None
|
||||||
|
|
||||||
# Try to login to Plex.tv to check if the user has a vaild account
|
# Try to login to Plex.tv to check if the user has a vaild account
|
||||||
if username and password:
|
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()
|
plex_user = plex_tv.get_token()
|
||||||
if plex_user:
|
if plex_user:
|
||||||
user_token = plex_user['auth_token']
|
user_token = plex_user['auth_token']
|
||||||
user_id = plex_user['user_id']
|
user_id = plex_user['user_id']
|
||||||
elif token:
|
elif token:
|
||||||
plex_tv = PlexTV(token=token)
|
plex_tv = PlexTV(token=token, headers=headers)
|
||||||
plex_user = plex_tv.get_plex_account_details()
|
plex_user = plex_tv.get_plex_account_details()
|
||||||
if plex_user:
|
if plex_user:
|
||||||
user_token = token
|
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.
|
# 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.
|
# 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()
|
server_token = plex_tv.get_server_token()
|
||||||
if server_token:
|
if server_token:
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ def user_login(username=None, password=None, token=None):
|
||||||
return 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.
|
"""Verifies credentials for username and password.
|
||||||
Returns True and the user group on success or False and no user group"""
|
Returns True and the user group on success or False and no user group"""
|
||||||
|
|
||||||
|
@ -131,13 +131,7 @@ def check_credentials(username=None, password=None, token=None, admin_login='0')
|
||||||
return True, user_details, 'admin'
|
return True, user_details, 'admin'
|
||||||
|
|
||||||
if plexpy.CONFIG.HTTP_PLEX_ADMIN or (not admin_login == '1' and plexpy.CONFIG.ALLOW_GUEST_ACCESS):
|
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)
|
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]
|
|
||||||
|
|
||||||
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:
|
if plex_login is not None:
|
||||||
return True, plex_login[0], plex_login[1]
|
return True, plex_login[0], plex_login[1]
|
||||||
|
|
||||||
|
@ -315,7 +309,8 @@ class AuthController(object):
|
||||||
valid_login, user_details, user_group = check_credentials(username=username,
|
valid_login, user_details, user_group = check_credentials(username=username,
|
||||||
password=password,
|
password=password,
|
||||||
token=token,
|
token=token,
|
||||||
admin_login=admin_login)
|
admin_login=admin_login,
|
||||||
|
headers=kwargs)
|
||||||
|
|
||||||
if valid_login:
|
if valid_login:
|
||||||
time_delta = timedelta(days=30) if remember_me == '1' else timedelta(minutes=60)
|
time_delta = timedelta(days=30) if remember_me == '1' else timedelta(minutes=60)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue