-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to Plex Authentication and User lists and Quality Profiles
- Updated PleX authentication method to use the new APIv2 - Plex authentication using Username or Email login now supported for all users - Fixed issue with Quality profiles not being persistent for both Sonarr and Radarr (About time!!) - Added a button to trigger a manual refresh of friends lists - Cleaned up the Users Ui Signed-off-by: Ricky Grassmuck <[email protected]>
- Loading branch information
1 parent
78ec50c
commit 8732b49
Showing
6 changed files
with
118 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,3 +85,7 @@ | |
background-color: #ccc; | ||
} | ||
} | ||
.item-divider { | ||
margin: inherit; | ||
margin-bottom: 1rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,134 +1,133 @@ | ||
Meteor.methods({ | ||
'checkPlexAuthentication' : function () { | ||
|
||
'checkPlexAuthentication': function () { | ||
return Settings.find({}).fetch()[0].plexAuthenticationENABLED | ||
}, | ||
'checkPlexAuthenticationPasswords' : function () { | ||
|
||
'checkPlexAuthenticationPasswords': function () { | ||
return Settings.find({}).fetch()[0].plexAuthenticationPASSWORDS | ||
}, | ||
'checkPlexUser' : function (plexUsername, plexPassword) { | ||
|
||
if (Settings.find({}).fetch()[0].plexAuthenticationPASSWORDS) { | ||
// If passwords are required check full login | ||
'plexLogin': function (username, password) { | ||
check(username, String) | ||
check(password, String) | ||
|
||
function authHeaderVal(username, password) { | ||
var authString = username + ':' + password | ||
var buffer = new Buffer(authString.toString(), 'binary') | ||
return 'Basic ' + buffer.toString('base64') | ||
} | ||
try { | ||
var requestAuth = Meteor.http.call('POST', 'https://plex.tv/api/v2/users/signin', { | ||
headers: { | ||
'Accept': 'application/json', | ||
'X-Plex-Client-Identifier': 'BGZQ8N25FYP3UHB6', | ||
'X-Plex-Version': '1.2.0', | ||
'X-Plex-Platform': 'Meteor', | ||
'X-Plex-Device-Name': 'Plex Requests' | ||
}, | ||
data: { | ||
'login': username, | ||
'password': password, | ||
'rememberMe': false | ||
} | ||
|
||
var headers = { | ||
'Authorization': authHeaderVal(plexUsername, plexPassword), | ||
'X-Plex-Client-Identifier': 'BGZQ8N25FYP3UHB6', | ||
'X-Plex-Version': '1.2.0', | ||
'X-Plex-Platform': 'Meteor', | ||
'X-Plex-Device-Name': 'Plex Requests' | ||
} | ||
}) | ||
|
||
try { | ||
Meteor.http.call('POST', 'https://plex.tv/users/sign_in.json', {headers: headers}) | ||
} catch (error) { | ||
logger.warn(plexUsername + ' failed to login') | ||
throw new Meteor.Error(401, JSON.parse(error.message.substring(13)).error) | ||
} | ||
|
||
var plexData = JSON.parse(requestAuth.content) | ||
|
||
|
||
} catch (error) { | ||
logger.error(plexData.errors[0].message) | ||
throw new Meteor.Error(401, plexData.errors.error[0]) | ||
} | ||
|
||
function isInArray(value, array) { | ||
return array.indexOf(value) > -1 | ||
if (requestAuth.statusCode === 201) { | ||
return plexData | ||
} | ||
|
||
function checkArray(value, array) { | ||
return array.indexOf(value) | ||
}, | ||
|
||
'checkPlexUser': function (plexLogin, plexPassword) { | ||
check(plexLogin, String) | ||
check(plexPassword, String) | ||
|
||
if (Settings.find({}).fetch()[0].plexAuthenticationPASSWORDS) { | ||
// If passwords are required check full login | ||
var userInfo = Meteor.call('plexLogin', plexLogin, plexPassword) | ||
var plexUsername = userInfo.username | ||
} | ||
|
||
//Update users in permissions | ||
Meteor.call('permissionsUpdateUsers') | ||
|
||
//Get friendslist and bannedlist | ||
var friendsList = Meteor.call('getPlexFriendlist') | ||
var bannedList = Permissions.find({permBANNED: true}, {fields: {_id: 0, permUSER: 1, permBANNED: 1}}).fetch() | ||
|
||
//Remove banned users | ||
for(var i = 0; i < bannedList.length; i++) { | ||
for (var i = 0; i < bannedList.length; i++) { | ||
friendsList.splice(friendsList.indexOf(bannedList[i].permUSER), 1) | ||
} | ||
return (isInArray(plexUsername.toLowerCase(), friendsList)) | ||
|
||
return (friendsList.indexOf(plexUsername.toLowerCase()) > -1) | ||
}, | ||
'getPlexToken' : function (username,password) { | ||
|
||
//clean password and username for authentication. | ||
function authHeaderVal(username, password) { | ||
var authString = username + ':' + password | ||
var buffer = new Buffer(authString.toString(), 'binary') | ||
return 'Basic ' + buffer.toString('base64') | ||
} | ||
'getPlexToken': function (plexLogin, plexPassword) { | ||
check(plexLogin, String) | ||
check(plexPassword, String) | ||
|
||
try { | ||
var plexstatus = Meteor.http.call('POST', 'https://plex.tv/users/sign_in.xml', { | ||
headers: { | ||
'Authorization': authHeaderVal(username, password), | ||
'X-Plex-Client-Identifier': 'BGZQ8N25FYP3UHB6', | ||
'X-Plex-Version': '1.2.0', | ||
'X-Plex-Platform': 'Meteor', | ||
'X-Plex-Device-Name': 'Plex Requests' | ||
} | ||
}) | ||
} catch (error) { | ||
var response = xml2js.parseStringSync(error.response.content) | ||
logger.error(response.errors.error[0]) | ||
throw new Meteor.Error(401, response.errors.error[0]) | ||
if (plexLogin !== '' && plexPassword !== '') { | ||
var userInfo = Meteor.call('plexLogin', plexLogin, plexPassword) | ||
var plexAuth = userInfo.authToken | ||
} else { | ||
logger.error('Missing login or password') | ||
throw new Meteor.Error(401, 'Must supply a valid login and password') | ||
} | ||
|
||
|
||
//Bad authentication comes back as 401, will need to add error handles, for now it just assumes that and lets user know | ||
if (plexstatus.statusCode==201) { | ||
var results = xml2js.parseStringSync(plexstatus.content) | ||
var plexAuth = results.user.$.authenticationToken | ||
Settings.update({}, {$set: {plexAuthenticationTOKEN: plexAuth}}) | ||
if (plexAuth) { | ||
Settings.update({}, {$set: {plexAuthenticationTOKEN: plexAuth}}) | ||
return true | ||
} else { | ||
logger.error('Error getting Plex token') | ||
return false | ||
} | ||
}, | ||
'getPlexFriendlist' : function () { | ||
|
||
'getPlexFriendlist': function () { | ||
var plexToken = Settings.find({}).fetch()[0].plexAuthenticationTOKEN | ||
|
||
try { | ||
var friendsXML = Meteor.http.call('GET', 'https://plex.tv/pms/friends/all?X-Plex-Token='+plexToken) | ||
var accountXML = Meteor.http.call('GET', 'https://plex.tv/users/account?X-Plex-Token='+plexToken) | ||
var friendsXML = Meteor.http.call('GET', 'https://plex.tv/pms/friends/all?X-Plex-Token=' + plexToken) | ||
var accountXML = Meteor.http.call('GET', 'https://plex.tv/users/account?X-Plex-Token=' + plexToken) | ||
} catch (error) { | ||
logger.error('Error checking Plex Users: ' + error.message) | ||
return false | ||
logger.error('Error checking Plex Users: ' + error.message) | ||
return false | ||
} | ||
|
||
var users = [] | ||
var admintitle = '' | ||
|
||
xml2js.parseString(friendsXML.content, {mergeAttrs : true, explicitArray : false} ,function (err, result) { | ||
xml2js.parseString(friendsXML.content, {mergeAttrs: true, explicitArray: false}, function (err, result) { | ||
users = result['MediaContainer']['User'] | ||
}) | ||
|
||
xml2js.parseString(accountXML.content, {mergeAttrs : true, explicitArray : false} ,function (err, result) { | ||
xml2js.parseString(accountXML.content, {mergeAttrs: true, explicitArray: false}, function (err, result) { | ||
admintitle = result['user']['title'].toLowerCase() | ||
}) | ||
|
||
var friendsList = [] | ||
|
||
// Check if an array of users or a single user is returned | ||
if (typeof users !== 'undefined'){ | ||
if (typeof users !== 'undefined') { | ||
if (users.length) { | ||
for (var i = 0; i < users.length; i++) { | ||
friendsList.push( users[i].title.toLowerCase() ) | ||
friendsList.push(users[i].title.toLowerCase()) | ||
} | ||
} else if (users.title) { | ||
friendsList.push( users.title.toLowerCase() ) | ||
} | ||
friendsList.push(users.title.toLowerCase()) | ||
} | ||
} | ||
|
||
//Add admin username to the list | ||
friendsList.push(admintitle) | ||
|
||
return(friendsList) | ||
return (friendsList) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters