Setup DiscourseConnect - Official Single-Sign-On for Discourse (sso)

It sounds like what you are doing is using Discourse as the SSO provider for WordPress. That approach is outlined here: Use Discourse as an identity provider (SSO, DiscourseConnect). The Discourse WordPress plugin has options for either using WordPress as the SSO provider for Discourse, or for using Discourse as an identity provider for WordPress. Using the same name for both approaches leads to some confusion.

I’d be tempted to use WordPress as the identity provider for this case. With that approach, users will create accounts on your WordPress site and then login to Discourse with their WordPress credentials. One thing to be aware of with this approach is that it means that users will only be able to log into Discourse through WordPress, it won’t be possible to create a Discourse account without already having a WordPress account. I think that’s the appropriate setup when integrating Discourse with a WordPress membership site.

When WordPress is used as the identity provider for Discourse, there are a couple of utility functions that are useful for setting user’s Discourse group memberships based on their activity on WordPress. Those functions are outlined here: Manage group membership in Discourse with WP Discourse SSO.

Going back to your original question:

It’s been a while since I looked at the WordPress plugin’s DiscourseConnect Client code, but I think what you are asking for is more or less the way that code is expected to work. If a user has a Discourse account, they just need to click the “Login through Discourse” link on WordPress and an account will be created for them.

This would be technically possible when using WordPress as the DiscourseConnect Client, but unless something has changed, you won’t be able to use the add_user_to_discourse_group and remove_user_from_discourse_group methods that are outlined in the documentation I linked to. You’d need to so something like setup a Discourse Webhook that was triggered when a user was added to a Discourse group, then add some code on WordPress to process that webhook. To sync groups from WordPress to Discourse, you’d need to make an API call to Discourse to update a user’s groups when there was a change on WordPress. So something that would be fairly easy to accomplish if you use Wordpress as the DiscourseConnect provider might be somewhat complicated if you use WordPress as the DiscourseConnect client.

1 Like