From 992ca1261c0c0c69339a9823ab9ab490a0aa3fee Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 4 Jun 2019 22:05:30 +0200 Subject: [PATCH] Implemented authenticating with plex helper function. Takes username and password --- src/seasonedAPI.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/seasonedAPI.js b/src/seasonedAPI.js index 2a06f2c..cefb0d4 100644 --- a/src/seasonedAPI.js +++ b/src/seasonedAPI.js @@ -62,6 +62,24 @@ const request = (id, type, authorization_token) => { } +// - - - Authenticate with plex - - - + +const plexAuthenticate = (username, password) => { + const url = `https://plex.tv/users/sign_in.json?user[login]=${username}&user[password]=${password}` + const headers = { + 'Content-Type': 'application/json', + 'X-Plex-Platform': 'Linux', + 'X-Plex-Version': 'v2.0.24', + 'X-Plex-Platform-Version': '4.13.0-36-generic', + 'X-Plex-Device-Name': 'Tautulli', + 'X-Plex-Client-Identifier': '123' + } + + return axios.post(url, { headers: headers }) + .catch(error => { console.error(`api error authentication plex: ${username}`); throw error }) +} + + // - - - Random emoji - - - const getEmoji = () => { @@ -72,4 +90,4 @@ const getEmoji = () => { -export { getMovie, getShow, getListByName, search, searchTorrents, request, getEmoji } +export { getMovie, getShow, getListByName, search, searchTorrents, request, plexAuthenticate, getEmoji }