mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 15:32:38 -07:00
Improve Plex OAuth
This commit is contained in:
parent
16bfcade8c
commit
745d398527
2 changed files with 60 additions and 29 deletions
|
@ -1,4 +1,7 @@
|
||||||
<!doctype html>
|
<%
|
||||||
|
import plexpy
|
||||||
|
%>
|
||||||
|
<!doctype html>
|
||||||
|
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
@ -144,39 +147,84 @@
|
||||||
|
|
||||||
getPlexOAuthURL = function () {
|
getPlexOAuthURL = function () {
|
||||||
var deferred = $.Deferred();
|
var deferred = $.Deferred();
|
||||||
$.get('get_plex_oauth_url').then(function (data) {
|
|
||||||
deferred.resolve(data);
|
$.ajax({
|
||||||
|
url: 'https://plex.tv/api/v2/pins?strong=true',
|
||||||
|
type: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'X-Plex-Product': 'Tautulli',
|
||||||
|
'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}'
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
const pin = data.id;
|
||||||
|
const code = data.code;
|
||||||
|
const url = 'https://app.plex.tv/auth/#!?clientID=f65c1d60d15347ac8c9999cca9643700&code=' + code;
|
||||||
|
data = {pin: pin, url: url };
|
||||||
|
deferred.resolve(data);
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
deferred.reject();
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
return deferred;
|
return deferred;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var polling = null;
|
||||||
$('#sign-in-plex').click(function() {
|
$('#sign-in-plex').click(function() {
|
||||||
|
clearTimeout(polling);
|
||||||
|
|
||||||
getPlexOAuthURL().then(function (data) {
|
getPlexOAuthURL().then(function (data) {
|
||||||
var url = data.url;
|
const url = data.url;
|
||||||
var pin = data.pin;
|
const pin = data.pin;
|
||||||
var polling = true;
|
var keep_polling = true;
|
||||||
|
|
||||||
window.open(url);
|
window.open(url);
|
||||||
|
|
||||||
(function poll() {
|
(function poll() {
|
||||||
setTimeout(function () {
|
polling = setTimeout(function () {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'pin/' + pin,
|
url: 'https://plex.tv/api/v2/pins/' + pin,
|
||||||
|
type: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'X-Plex-Product': 'Tautulli',
|
||||||
|
'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}'
|
||||||
|
},
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (data.result === 'success'){
|
if (data.authToken){
|
||||||
polling = false;
|
keep_polling = false;
|
||||||
signIn(true, data.token)
|
signIn(true, data.authToken);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
error: function () {
|
||||||
|
keep_polling = false;
|
||||||
|
$('#sign-in-plex-alert').text('Error communicating with Plex.tv.').show();
|
||||||
|
},
|
||||||
complete: function () {
|
complete: function () {
|
||||||
if (polling){
|
if (keep_polling){
|
||||||
poll();
|
poll();
|
||||||
|
} else {
|
||||||
|
clearTimeout(polling);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
timeout: 1000
|
timeout: 1000
|
||||||
});
|
});
|
||||||
}, 1000);
|
}, 1000);
|
||||||
})();
|
})();
|
||||||
|
}, function () {
|
||||||
|
$('#sign-in-plex-alert').text('Error communicating with Plex.tv.').show();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -359,20 +359,3 @@ class AuthController(object):
|
||||||
logger.debug(u"Tautulli WebAuth :: Invalid Plex OAuth login attempt.")
|
logger.debug(u"Tautulli WebAuth :: Invalid Plex OAuth login attempt.")
|
||||||
cherrypy.response.status = 401
|
cherrypy.response.status = 401
|
||||||
return error_message
|
return error_message
|
||||||
|
|
||||||
@cherrypy.expose
|
|
||||||
@cherrypy.tools.json_out()
|
|
||||||
def get_plex_oauth_url(self, *args, **kwargs):
|
|
||||||
pin = PlexTV().get_pin()
|
|
||||||
oauth_url = 'https://app.plex.tv/auth/#!?clientID={}&code={}'.format(
|
|
||||||
plexpy.CONFIG.PMS_UUID, pin['code'])
|
|
||||||
return {'pin': pin['id'], 'url': oauth_url}
|
|
||||||
|
|
||||||
@cherrypy.expose
|
|
||||||
@cherrypy.tools.json_out()
|
|
||||||
def pin(self, pin=None, *args, **kwargs):
|
|
||||||
pin = PlexTV().get_pin(pin=pin)
|
|
||||||
if pin['token']:
|
|
||||||
return {'result': 'success', 'token': pin['token']}
|
|
||||||
else:
|
|
||||||
return {'result': 'polling'}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue