Using Plex PIN with my custom app

So I’m writing a comprehensive app (skill) for the Amazon Echo to allow Plex Users to control everything in Plex by voice. Basically it lets you ask Alexa what’s On Deck and start playing TV Shows/Movies and Music Albums by name to whatever TV or device you want to play it on. Such as “Alexa, play the movie Ghostbusters on my Bedroom TV”. The app is still in it’s early stages, but I have gotten it working and have read enough documentation to know I can program it to do everything Plex has to offer thanks to the XML API.

I want to make this application public so all Plex users with an Amazon Echo can control their media via Alexa voice commands.

Unfortunately, I have to set the X-Plex-Token to query PMS for information… and I am able to get the server to create a token for me based on my username/password. However, that authentication information is currently stored as a variable in my code. What I want to do instead, is provide the user with a PIN number when they install this Skill on their Amazon Echo and have them go to http://plex.tv/pin to enter that code, which will then return a token for the application /skill to use.

Can you guys help me figure out how to request a PIN for use with http://plex.tv/pin so that people who download my app can get a token for their app to communicate with their Plex Media Server?

I figured it out.

You gotta do a POST to pins.xml with a X-Plex-Client-Indentifier specified, such as:
https://plex.tv/pins.xml?X-Plex-Client-Identifier=Alexa-to-Plex-Integration

You get some XML back from that, and in there is a “code” and an “id type” field that you need to capture the value of.
9X9Y
55511001

Then you do a GET to /pins/“id type” with your X-Plex-Client-Identifier.
https://plex.tv/pins/55511001?X-Plex-Client-Identifier=Alexa-to-Plex-Integration

The result of that GET will be some JSON with a field called “auth_token” and that’s what you’re after. It will return a null value until the user goes to https://plex.tv/pin logged in with their plex account and enters in the PIN provided such as “9X9Y”… you keep doing the GET until a non-null auth_token is returned. Once returned they’ve logged in, used the PIN, and created an auth_token for your device.

What I’m not sure of, is if this X-Plex-Client-Identifier can be hard-coded in my program so all users use the same one, or if I need to randomize it for every user. I’m pretty sure I can just set it to a single value for everyone, since if I run it back to back it gives me different id type and code values.

This sounds very interesting. Any progress or availability to report?

Thanks