I want to create a forum for my plex friends and I want them to login with their Plex account. But only those that I’ve shared one or more libraries with.
I decided to go with discourse since they have great SSO capabilities. I can program with PHP, Javascript and jQuery, however I’m not sure how to approach this exactly. Can someone lay out the steps required?
I would love to let the users use the default Plex login page in which case I can imagine it goes something like this:
Redirect to Plex login page
After succesful login: redirect to a page I maintain, where I can confirm authentication to my Plex server.
If succesful I can redirect it back to the discourse forum with all necessary meta data attached.
Just for future reference if anyone wants to do the same, I was able to do what I wanted with the following steps:
Send a post request to https://plex.tv/users/sign_in.json according to this post to get a Plex token. A PHP example can be found here. See the getPlexToken function. Thanks @hjone72 for the link.
With the obtained token the page https://plex.tv/pms/servers.xml?X-Plex-Token=plex-token-here can be accessed through a standard get request. I viewed the source for myself and noticed my server’s machineIdentifier. Note that down.
For other users just iterate through their servers. If a machineIdentifier matches yours they succesfully logged in and confirmed access to your server.
From the first step you can also get some meta data like thumb, username, etc. Now it’s just a matter of delivering the information to discourse.