# 将 Discourse 用作身份提供者 (SSO, DiscourseConnect)

**URL:** <https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974>\
**Category:** Integrations\
**Tags:** sso, discourseconnect, how-to\
**Created:** [2015年九月7日 09:19 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974 "2015-09-07T09:19:21Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)\
**Post date:** [2016年十一月28日 11:50 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/22 "2016-11-28T11:50:15Z")

</div>

Our official WordPress plugin provides SSO functionality. See:

> **[WP Discourse](https://wordpress.org/plugins/wp-discourse/)**
>
> This plugin allows you to use Discourse as a community engine for your WordPress website. The plugin is not a substitute for Disqus type commenting sy …

---

<div class="post-metadata">

**Author:** ![Sveinn\_S](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sveinn_s/32/121398_2.png) [@Sveinn\_S](https://meta.discourse.org/u/Sveinn_S)\
**Post date:** [2016年十一月28日 15:01 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/23 "2016-11-28T15:01:09Z")

</div>

Is there a way to make the [WP Discourse](https://github.com/discourse/wp-discourse) make wordpress use Discourse as the SSO provider. It looks to me like it is the other way around. As it makes Discourse use wordpress as the SSO.  
I already have users set up in discourse and I have an aplication that I would like to give my forum users access to without having them set up their accounts again in wordpress.

---

<div class="post-metadata">

**Author:** ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)\
**Post date:** [2016年十一月28日 15:21 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/24 "2016-11-28T15:21:56Z")

</div>

Sorry, I misread your question above.

There is currently no WordPress plugin that provides “Login with Discourse” functionality.

That said, I think you can create one easily using this PHP script (by @paxmanchris) as base:

> <https://gist.github.com/paxmanchris/e93018a3e8fbdfced039>

---

<div class="post-metadata">

**Author:** ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)\
**Post date:** [2016年十一月28日 17:08 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/25 "2016-11-28T17:08:15Z")

</div>

This would be a great contribution and I would use it if it existed. I think it would a great addition to the [wp discourse](https://github.com/discourse/wp-discourse) plugin as an option. The discourse login system is far superior to wordpress.

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2016年十一月28日 17:09 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/26 "2016-11-28T17:09:17Z")

</div>

This seems like a fairly popular request. It would be great if the Wordpress Plugin would handle this as well.

The other thing that I get requests for is having Wordpress as an **optional** authentication source (along side of Google and others).

---

<div class="post-metadata">

**Author:** ![Gunnar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gunnar/32/119647_2.png) [@Gunnar](https://meta.discourse.org/u/Gunnar)\
**Post date:** [2016年十二月4日 04:30 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/27 "2016-12-04T04:30:07Z")

</div>

We need this as well (Discourse as SSO provider for Wordpress). I can provide a $500 bounty, if that would help?

The code would need to provide an implementation good enough to be included in the [WP Discourse](https://github.com/discourse/wp-discourse) plugin. We do not want to be running custom code in either Discourse or WP, just “official” code and supported plugins. Obviously, the code would have to be released to the community.

Any takers?

Gunnar

---

<div class="post-metadata">

**Author:** ![iamntz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/iamntz/32/114670_2.png) [@iamntz](https://meta.discourse.org/u/iamntz)\
**Post date:** [2016年十二月4日 12:26 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/28 "2016-12-04T12:26:47Z")

</div>

I did this plugin few months ago, but I didn’t knew is such a demand for this, so I didn’t published anywhere. 🙂

Here it is:

[https://github.com/iamntz/discourse-sso-provider-for-wp](https://github.com/iamntz/discourse-sso-provider-for-wp)

In order to minimize duplication, this plugin **requires** wp-discourse to be installed. If that’s not good, I can tweak it to add custom fields to it.

---

<div class="post-metadata">

**Author:** ![erlend\_sh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/erlend_sh/32/119475_2.png) [@erlend\_sh](https://meta.discourse.org/u/erlend_sh)\
**Post date:** [2016年十二月4日 13:29 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/29 "2016-12-04T13:29:23Z")

</div>

Great! Could you repurpose this code as a PR against [wp-discourse](https://github.com/discourse/wp-discourse)? That way users could get it straight from the WP plugin repo, and we could help you maintain the code.

I think a dependency on wp-discourse should be fine since that’s our canonical WordPress plugin and SSO functionality can become a security hazard if it goes stale.

---

<div class="post-metadata">

**Author:** ![iamntz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/iamntz/32/114670_2.png) [@iamntz](https://meta.discourse.org/u/iamntz)\
**Post date:** [2016年十二月4日 16:43 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/30 "2016-12-04T16:43:39Z")

</div>

Well, then…

[https://github.com/discourse/wp-discourse/pull/257](https://github.com/discourse/wp-discourse/pull/257)

Later edit:

Finished linting, added documentation, I think I’m done.

I only need some testers to install it, set it up and play around to know if it’s all good.

Even later edit:

- also added _Log in with Discourse_ link on login form;
- added errors if email from your discourse account is already in the db.

 ![](https://global.discourse-cdn.com/meta/original/3X/b/a/bae8463a2301cb51c6390f50ecd0109c82e7612c.jpg)

 ![](https://global.discourse-cdn.com/meta/original/3X/7/d/7d0a790aa552fc0fbe2a31bb12e91eeb74a0a64c.jpg)

cc @Gunnar

---

<div class="post-metadata">

**Author:** ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)\
**Post date:** [2016年十二月8日 05:11 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/31 "2016-12-08T05:11:05Z")

</div>

This is shweet! Nice work. 🚀 I’m eager to see it in the wild somewhere and help with testing. Feel free to PM me if you’d like help with testing, or share links where this is being used now here.

---

<div class="post-metadata">

**Author:** ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)\
**Post date:** [2016年十二月30日 18:13 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/32 "2016-12-30T18:13:02Z")

</div>

I have yet to see the wp-discourse using discourse as sso provider functionality in the wild and would love to do so. Anyone have a link?

I’m very interested in allowing members to log in via discourse (and consequently via discourse social logins using twitter, facebook etc) but following the [discussion about it on github](https://github.com/discourse/wp-discourse/pull/257) it seems my use case is not supported.

Upon login, if the account does not already exist in wordpress, I’d like to kick the user over to the signup form on wordpress, which has some customizations on our side to deal with synchronization of profile details from wordpress to discourse upon signup, along with a custom welcome PM. It works quite well and I don’t want to mess with it too much. I suspect this is not such a rare setup.

I don’t think your functionality offers support for this type of setup so far.

Maybe I need to find a different wordpress plugin to handle social logins even if it means bypassing discourse’s quite amazing social login functionality which would be a shame. If anyone has done this already and has tips, I’d appreciate it.

---

<div class="post-metadata">

**Author:** ![iamntz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/iamntz/32/114670_2.png) [@iamntz](https://meta.discourse.org/u/iamntz)\
**Post date:** [2016年十二月31日 11:58 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/33 "2016-12-31T11:58:24Z")

</div>

> [@tobiaseigen](#):
>
> Upon login, if the account does not already exist in wordpress, I’d like to kick the user over to the signup form on wordpress

So basically you want to disable SSO auth for new users? If so, this is possible by unchecking _Add “Login with Discourse” on the login form_ and add this line on your `functions.php` file:

```plaintext
add_filter('discourse/sso/provider/add_link_buttons_on_profile', '__return_true');

```

---

<div class="post-metadata">

**Author:** ![Biarity](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/biarity/32/121215_2.png) [@Biarity](https://meta.discourse.org/u/Biarity)\
**Post date:** [2017年一月26日 01:47 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/34 "2017-01-26T01:47:45Z")

</div>

I just published a really easy to use implementation of this: [GitHub - Biarity/DiscourseSso: Easy, configurable Discourse SSO: GET /auth/login -\> recieve a JWT with user data · GitHub](https://github.com/Biarity/DiscourseSso).

Essentially you just add configuration, make a request to `GET /auth/login`, and receive a JWT authenticating the user.

It’s built on [ASP.NET](http://ASP.NET) Core but can be used with any tech stack since you needn’t touch the code to get this working.

---

<div class="post-metadata">

**Author:** ![Biarity](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/biarity/32/121215_2.png) [@Biarity](https://meta.discourse.org/u/Biarity)\
**Post date:** [2017年一月26日 05:46 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/35 "2017-01-26T05:46:30Z")

</div>

I’m trying to look for something that’s unique and persistent (can’t be changed by the user) to identify users & store data unique to each user.

Apparently a user can change their username so that won’t work. I found a property `external_id` but I’m not sure what it is; seems to be unique & unchangeable though, so is that what I’m looking for?

---

<div class="post-metadata">

**Author:** ![JagWaugh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagwaugh/32/69335_2.png) [@JagWaugh](https://meta.discourse.org/u/JagWaugh)\
**Post date:** [2017年二月17日 16:40 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/36 "2017-02-17T16:40:34Z")

</div>

I’m running discourse v1.8.0.beta5 +39 and wordpress 4.7.2 with the wp-discourse 1.1.3 plugin installed.

When I go to configure the plugin I do not see the Enable [Discourse SSO](https://meta.discourse.org/t/13045?silent=true) checkbox at all:

 ![](https://global.discourse-cdn.com/meta/original/3X/3/7/376a32bcb8fec95db8b818bd23d415ba4f44a538.png)

The SSO functionality does work between the two.

I’m trying to enable SSO from Discourse. What have I missed?

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2017年二月17日 17:04 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/37 "2017-02-17T17:04:43Z")

</div>

The latest version isn’t in the WordPress plugin repo yet. I’ll push it there tomorrow. If you want to try it now you can get it from here: [GitHub - discourse/wp-discourse: WordPress plugin that lets you use Discourse as the community engine for a WordPress blog · GitHub](https://github.com/discourse/wp-discourse)

---

<div class="post-metadata">

**Author:** ![JagWaugh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagwaugh/32/69335_2.png) [@JagWaugh](https://meta.discourse.org/u/JagWaugh)\
**Post date:** [2017年二月19日 02:54 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/38 "2017-02-19T02:54:08Z")

</div>

So, the version in the plugin repo works (WOO HOO!).

One minor issue, it doesn’t populate the “Website” or “Discourse Username” fields.

Although I can _sort of_ imagine that some installations might not want absolutely everything in the WP profile to be duplicated from the Discourse Profile, surely the “Discourse Username” should be mapped.

Perhaps a series of checkboxes for what Discourse Profile fields should be mapped (Username, Website, Avatar) would be in order.

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2017年二月19日 02:55 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/39 "2017-02-19T02:55:24Z")

</div>

> [@JagWaugh](#):
>
> it doesn’t populate the “Website” or “Discourse Username” fields

That’s coming in the next few days.

Edit: I’ve set it up to set the Discourse username. I’ll push the changes to the WordPress repo tomorrow.

---

<div class="post-metadata">

**Author:** ![chris062689](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chris062689/32/120174_2.png) [@chris062689](https://meta.discourse.org/u/chris062689)\
**Post date:** [2017年三月3日 15:13 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/40 "2017-03-03T15:13:53Z")

</div>

Is there additional documentation on the Node.js Passport repository? There seems to be quite a few issues with it. Is there an alternative way for me to use Discourse as an SSO provider in Node through passport?  
Any alternatives for Node.js?

---

<div class="post-metadata">

**Author:** ![erlend\_sh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/erlend_sh/32/119475_2.png) [@erlend\_sh](https://meta.discourse.org/u/erlend_sh)\
**Post date:** [2017年三月3日 18:35 UTC](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974/41 "2017-03-03T18:35:47Z")

</div>

Did you try reach @edhemphill either here on Meta or [on GitHub](https://github.com/edhemphill/passport-discourse) by raising an issue?

[上一頁](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974.md?page=1)

[下一頁](https://meta.discourse.org/t/use-discourse-as-an-identity-provider-sso-discourseconnect/32974.md?page=3)
