# Discourse SSO with Plex, how would it work?

**URL:** <https://forums.plex.tv/t/discourse-sso-with-plex-how-would-it-work/210623>\
**Category:** Dev/API Corner\
**Tags:** other-dev\
**Created:** [October 18, 2017, 11:18am UTC](https://forums.plex.tv/t/discourse-sso-with-plex-how-would-it-work/210623 "2017-10-18T11:18:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Serik](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/serik/32/83159_2.png) [@Serik](https://forums.plex.tv/u/Serik)\
**Post date:** [October 18, 2017, 11:18am UTC](https://forums.plex.tv/t/discourse-sso-with-plex-how-would-it-work/210623/1 "2017-10-18T11:18:54Z")

</div>

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](https://www.discourse.org/ "discourse") since they have [great SSO capabilities](https://meta.discourse.org/t/official-single-sign-on-for-discourse-sso/13045 "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:

1. Redirect to Plex login page
2. After succesful login: redirect to a page I maintain, where I can confirm authentication to my Plex server.
3. If succesful I can redirect it back to the discourse forum with all necessary meta data attached.
4. User is logged in.

---

<div class="post-metadata">

**Author:** ![hjone72](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/hjone72/32/85715_2.png) [@hjone72](https://forums.plex.tv/u/hjone72)\
**Post date:** [October 18, 2017, 11:05pm UTC](https://forums.plex.tv/t/discourse-sso-with-plex-how-would-it-work/210623/2 "2017-10-18T23:05:18Z")

</div>

This would require Plex’s support.

The closest thing you could achieve would be: [github.com/causefx/Organizr](http://github.com/causefx/Organizr) or [github.com/hjone72/PlexAuth](http://github.com/hjone72/PlexAuth)

---

<div class="post-metadata">

**Author:** ![Serik](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/serik/32/83159_2.png) [@Serik](https://forums.plex.tv/u/Serik)\
**Post date:** [October 19, 2017, 3:00pm UTC](https://forums.plex.tv/t/discourse-sso-with-plex-how-would-it-work/210623/3 "2017-10-19T15:00:43Z")

</div>

Just a sidenote: the Plex sign-in page isn’t a requirement. It would just be nice. But whatever works best.

Those 2 projects are a nice way to start. I’ll take a look and see if that can help me out. Thanks.

---

<div class="post-metadata">

**Author:** ![Serik](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/serik/32/83159_2.png) [@Serik](https://forums.plex.tv/u/Serik)\
**Post date:** [October 23, 2017, 8:01pm UTC](https://forums.plex.tv/t/discourse-sso-with-plex-how-would-it-work/210623/4 "2017-10-23T20:01:16Z")

</div>

Just for future reference if anyone wants to do the same, I was able to do what I wanted with the following steps:

1. Send a post request to `https://plex.tv/users/sign_in.json` according to [this post](https://forums.plex.tv/discussion/129922/how-to-request-a-x-plex-token-token-for-your-app#latest "this post") to get a Plex token. A PHP example can be found [here](https://github.com/hjone72/PlexAuth/blob/master/inc/PlexUser.class.php "here"). See the `getPlexToken` function. Thanks @hjone72 for the link.
2. 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.
3. 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.

Also a very helpfull link: [https://github.com/Arcanemagus/plex-api/wiki](https://github.com/Arcanemagus/plex-api/wiki)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [January 8, 2020, 8:05pm UTC](https://forums.plex.tv/t/discourse-sso-with-plex-how-would-it-work/210623/5 "2020-01-08T20:05:36Z")

</div>


