0.1.0 • Published 8 years ago

plex-api-pinauth v0.1.0

Weekly downloads
9
License
MIT
Repository
github
Last release
8 years ago

node-plex-api-pinauth

An authentication module for node-plex-api that handles the API requests necessary for getting an auth token using a PIN.

Current State

It's usable, but it's ugly. One of the public methods returns a promise while the other uses a callback. That's dumb. There are other dumb things too that need to be cleaned up.

But it works!

Pull requests are very welcome.

Usage

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"
    }
});