An authentication module for node-plex-api that provides an interface for authenticating with Plex using a PIN, like the official clients do.
npm install plex-api-pinauthjs
var plexApi = require('plex-api');
var plexPinAuth = require('plex-api-pinauth')();
var plexClient = new PlexAPI({
hostname: '192.168.0.1',
authenticator: plexPinAuth
});
// Use getNewPin to get a new PIN object with these parameters:
// code: The 4-digit PIN that the user should enter on https://plex.tv/pin to grant authorization
// id: the ID of the PIN, which you'll need to use when checking if we have authorization yet
plexPinAuth.getNewPin().then(function(pinObj){
console.log(pinObj)
// {code: 'ABCD', id: '12345678'}
});
// Use checkPinForAuth to check to see if the user has entered the PIN on the website yet.
// returns a string representing 3 possible results:
// "authorized": The user has granted authorization and we now have the token. You can use plexClient now.
// "waiting": The user has not yet granted authorization.
// "invalid": The PIN is no longer (or never was) valid. PINs only remain valid for about 10 minutes.
plexPinAuth.checkPinForAuth(pinObj, function callback(err, status) {
if(err) {
// uh oh
} else {
console.log(status);
// "authorized"
}
});
``