Overview
This library is used to work with Plex OAuth to get an auth token used for making requests to a Plex server's API
As a note, these auth tokens should not be public. If you are making an app using a Plex auth token, it is recommended to not use the auth token on a frontend. If you need to authenticate a frontend system, then you should use the Plex auth token on the backend to make requests to the Plex server and use a different type of authentication for the frontend that will work with the Plex auth token on the backend.
Installation
You can install this package through npm
npm install plex-oauth
Usage
There are only 2 main functions to use in the PlexOauth
class (requestHostedLoginURL
& checkForAuthToken
). These will both return promises. If either of these functions throw an error, it needs to be explicitly caught with a try/catch
or using .catch(err)
on the promise itself.
Please look at the following example of how to get the Plex hosted login UI URL and how to query for the auth token:
import { PlexOauth, IPlexClientDetails } from "plex-oauth"
let clientInformation: IPlexClientDetails = {
origin: "https://localhost"
clientIdentifier: "<PROVIDE_UNIQUE_VALUE>",
product: "<NAME_OF_YOUR_APP>",
device: "<NAME_OF_YOUR_DEVICE>",
version: "1",
forwardUrl: "https://localhost:3000",
platform: "Web",
}
let plexOauth = new PlexOauth(clientInformation);
plexOauth.requestHostedLoginURL().then(data => {
let [hostedUILink, pinId] = data;
console.log(hostedUILink);
plexOauth.checkForAuthToken(pinId).then(authToken => {
console.log(authToken);
}).catch(err => {
throw err;
});
}).catch(err => {
throw err;
});