# Wordpress SSO AND Patreon Login

**URL:** https://meta.discourse.org/t/wordpress-sso-and-patreon-login/156292
**Category:** WordPress
**Created:** [June 29, 2020, 9:45pm UTC](https://meta.discourse.org/t/wordpress-sso-and-patreon-login/156292 "2020-06-29T21:45:50Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![chrislamdesign](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@chrislamdesign](https://meta.discourse.org/u/chrislamdesign)
#### Post date: [June 29, 2020, 9:45pm UTC](https://meta.discourse.org/t/wordpress-sso-and-patreon-login/156292/1 "2020-06-29T21:45:50Z")

</div>

Hi again! I had a question. A client of mine wants to gradually move his membership from Patreon to Wordpress (via Woocommerce Memberships). I know this is possible based on other forum posts.

However, my question is, if we enable SSO with Wordpress as the provider, is wordpress the ONLY way to sign into the forums? Would enabling SSO with Wordpress no longer allow Patreon users to sign in via their Patreon accounts? Or, is it possible to have both running together?

Sorry if this is confusing or the wrong place to be asking this.

Thanks in advance!

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [June 29, 2020, 9:53pm UTC](https://meta.discourse.org/t/wordpress-sso-and-patreon-login/156292/2 "2020-06-29T21:53:30Z")

</div>

Yes, the first S in SSO is Single. Wordpress becomes authoritative for all authentication.

That said, if Patreon is providing user email addresses the users can register on Wordpress to get back into their accounts providing the use the same address.

---

<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: [June 29, 2020, 9:58pm UTC](https://meta.discourse.org/t/wordpress-sso-and-patreon-login/156292/3 "2020-06-29T21:58:17Z")

</div>

You could also allow users to login to your WordPress site via Patreon with [Patreon WordPress – WordPress plugin | WordPress.org](https://wordpress.org/plugins/patreon-connect/). I have not tested this, but it should be possible to allow users to login to WordPress via Patreon while still having SSO login between WordPress and Discourse. If you try that and have any problems getting it to work, please let us know.

---

<div class="post-metadata">

### Author: ![morevnaproject](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/morevnaproject/32/171168_2.png) [@morevnaproject](https://meta.discourse.org/u/morevnaproject)
#### Post date: [March 2, 2021, 11:25am UTC](https://meta.discourse.org/t/wordpress-sso-and-patreon-login/156292/4 "2021-03-02T11:25:17Z")

</div>

> [@simon](#):
>
> You could also allow users to login to your WordPress site via Patreon with [Patreon WordPress – WordPress plugin | WordPress.org](https://wordpress.org/plugins/patreon-connect/).

Hi! I have tested this setup and it basically works! 🙂  
The only issue I found is that it doesn’t redirects to Discourse after successful login - it returns user to wordpress. User have to manually go to Discourse and then hit “Log In” button again to get registered. I wonder if this can be fixed somehow?

I have recorded the video to show how it works -

[![](https://global.discourse-cdn.com/meta/original/3X/2/0/20fe18f9f3e39979547c0702b1a92a0b913b3eca.jpeg "discourse patreon-wordpress sso") ](https://www.youtube.com/watch?v=XNv1-2sbvIA)

---

<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: [March 3, 2021, 1:56am UTC](https://meta.discourse.org/t/wordpress-sso-and-patreon-login/156292/5 "2021-03-03T01:56:05Z")

</div>

> [@morevnaproject](#):
>
> Hi! I have tested this setup and it basically works! 🙂  
> The only issue I found is that it doesn’t redirects to Discourse after successful login

Thanks for trying that. It sounds like the SSO parameters that are required for logging the user into Discourse are getting stripped during the Patreon login process. If that is the case, there probably isn’t anything that can be done to fix the issue.

---

<div class="post-metadata">

### Author: ![morevnaproject](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/morevnaproject/32/171168_2.png) [@morevnaproject](https://meta.discourse.org/u/morevnaproject)
#### Post date: [March 3, 2021, 6:27pm UTC](https://meta.discourse.org/t/wordpress-sso-and-patreon-login/156292/6 "2021-03-03T18:27:43Z")

</div>

I wonder, can this be fixed by modifying Wordpress-Patreon plugin? Does it worth to contact its authors? 🙂

---

<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: [March 3, 2021, 6:44pm UTC](https://meta.discourse.org/t/wordpress-sso-and-patreon-login/156292/7 "2021-03-03T18:44:40Z")

</div>

> [@morevnaproject](#):
>
> I wonder, can this be fixed by modifying Wordpress-Patreon plugin?

If the cause of the issue is what I think it is, then modifying the WordPress Patreon plugin could fix the issue. What I think is causing the problem is that the WordPress Patreon plugin is stripping the `sso` and `sig` query parameters that are sent with the Patreon login request. It could be worth contacting that plugin’s developers about the issue.

Before doing that, you should confirm that clicking the Login button on _Discourse_, for a user who is not currently logged into WordPress takes the user to the WordPress login page. If the user then selects the Patreon login option, they are logged into WordPress but not logged into Discourse. Note that if your Discourse site is set to be private, the above should happen if a user browses directly to your Discourse site. For that case, the user will not see a Login button on Discourse.

---

<div class="post-metadata">

### Author: ![morevnaproject](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/morevnaproject/32/171168_2.png) [@morevnaproject](https://meta.discourse.org/u/morevnaproject)
#### Post date: [April 5, 2021, 9:46am UTC](https://meta.discourse.org/t/wordpress-sso-and-patreon-login/156292/8 "2021-04-05T09:46:22Z")

</div>

Hi! I have submitted report to Patreon Plugin developers - [Redirecting not working when using together with Discourse SSO - Wordpress Plugin - Patreon Developers](https://www.patreondevelopers.com/t/redirecting-not-working-when-using-together-with-discourse-sso/4365)

> [@simon](#):
>
> Before doing that, you should confirm that clicking the Login button on _Discourse_ , for a user who is not currently logged into WordPress takes the user to the WordPress login page. If the user then selects the Patreon login option, they are logged into WordPress but not logged into Discourse.

Yes, I can confirm that:

- _clicking the Login button on Discourse , for a user who is not currently logged into WordPress takes the user to the WordPress login page_ - ✅ **YES**

- _If the user then selects the Patreon login option, they are logged into WordPress_ - ✅ **YES**

- _but not logged into Discourse_ - ✅ **YES** - on [the video above at 0:32](https://www.youtube.com/watch?v=XNv1-2sbvIA&t=32s) it shows the user is not logged in.

---

<div class="post-metadata">

### Author: ![morevnaproject](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/morevnaproject/32/171168_2.png) [@morevnaproject](https://meta.discourse.org/u/morevnaproject)
#### Post date: [April 7, 2021, 4:05am UTC](https://meta.discourse.org/t/wordpress-sso-and-patreon-login/156292/9 "2021-04-07T04:05:15Z")

</div>

Okay, I have found a workaround, which is “fixes” the issue with Patreon login. Please find instructions below. 🙂

You will need:

- Any plugin, which provides a shortcode to display login form (I have WooCommerce installed on my site, so I used `[woocommerce_my_account]` shortcode, which does exactly this for non-logged in users).
- [Members plugin](https://wordpress.org/plugins/members/), which provides `[members_logged_in]` and `[members_not_logged_in]` shortcodes to hide/show content depending on if user is logged in or not. You can use any other plugin which provides similar shortcodes functionality.
- [Shortcode Redirect plugin](https://wordpress.org/plugins/shortcode-redirect/).

The idea is to create a special page, which displays a login form (and Patreon login button) for non-logged in users. And if user is logged in, then it should redirect to '[https://community.morevnaproject.org/session/sso?return\_path=%2F`](https://community.morevnaproject.org/session/sso?return_path=%2F%60) url.  
(Obviously, you will want to replace “[community.morevnaproject.org](http://community.morevnaproject.org)” with your own domain).

My special login page has the following content:

```plaintext
[members_not_logged_in]
   [woocommerce_my_account]
   [patreon_login_button]
[/members_not_logged_in]
[members_logged_in]
   [redirect url='https://community.morevnaproject.org/session/sso?return_path=%2F' sec='0']
[/members_logged_in]

```

(you can see it in action here - [Log In / Register — Morevna Project](https://morevnaproject.org/log-in-discourse/))

Then, all you need is to configure WP-Discourse plugin to use that page for SSO -

 ![screenshot_001](https://global.discourse-cdn.com/meta/original/3X/d/b/db4a81d732eaab87572542190c3f7a5fc10e6ea4.png)

When user clicks “Log In” button in Discourse, he is redirected to my special Wordpress page. As the user is not logged in, it displays login form. If user clicks “Log in wiht Patreon” button, then he is redirected to Patreon for authorization. After successful authorization he is redirected back to my special page. SInce user is now logged in, then “redirect” shortcode is activated:

```plaintext
[redirect url='https://community.morevnaproject.org/session/sso?return_path=%2F' sec='0']

```

…and user successfully redirected back to discourse forums.

The `session/sso?return_path=%2F` part at the end of URL is required, otherwise Discourse will not recognizes user as logged in after redirect.

That’s it! I hope this will help other users, who want to have Wordpress SSO with Patreon Login on their website. 🙂

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [April 7, 2021, 12:16pm UTC](https://meta.discourse.org/t/wordpress-sso-and-patreon-login/156292/10 "2021-04-07T12:16:07Z")

</div>

Nice work in figuring that out 👍

I don’t want to detract from the work you’ve done, but my first take on this is that you should consider using an external auth service (such as [okta.com](http://okta.com) or [auth0.com](http://auth0.com)) at this point. Whenever you reach the point of connecting three different services (e.g. Patreon, Wordpress and Discourse) to achieve a single authentication in one go, it’s a sign you should be considering a dedicated authentication solution. Whether or not you can achieve it somehow, there’s a decent long-tail risk here that your solution will break down, or not work in all cases.

If you still want to go down this path, I have some suggestions, but fair warning that this is going to get a bit technical. I’m partly adding these here in case anyone else comes across this and wants to take this further.

I took a quick look at the [Patreon Wordpress Plugin code](https://github.com/Patreon/patreon-wordpress) and it looks like their OAuth flow accepts a `final_redirect_uri` key/value in the `state` param which would allow you to go directly from Patreon authentication to [Discourse SSO](https://meta.discourse.org/t/13045?silent=true), removing the need for both the Members and Redirect plugins mentioned above, and eliding any issues that may arise with that approach.

Many authentication services have a version of the `final_redirect_uri` parameter, i.e. a parameter which will allow you to change where the user is sent after authentication. If you’re reading this because you’re trying to solve the same problem, but with a different service (i.e other than Patreon), and you’ve also decided that my warning against connecting 3 different services doesn’t apply, then that is where you should look.

That means you’d want the shortcode that generates the Patreon login button to accept a `final_redirect_uri` as an argument, which would then be passed down to the eventual login url used by Patreon. Looking at the Patreon Wordpress Plugin code, that’s a feasible proposition. To give you a sense, the relevant function that generates the Patreon url looks like this:

```plaintext
Patreon_Frontend::patreonMakeLoginLink(false, array( 'final_redirect_uri' => # ) );

```

Basically, the code is already partially set up to handle a custom `final_redirect_uri`. I can understand why the Patreon Wordpress Plugin developers might not want to add it, but if you feel you’re confident enough with describing what I’ve described here, it might be worth creating an issue on [their github repostiory](https://github.com/Patreon/patreon-wordpress). Failing that, you can use that function I’ve referenced above to generate a link yourself and create your own button (or hire a Wordpress developer to do that).

Just a minor note on the sso url construction, it’s a bit clearer to use

```plaintext
https://discourse.example.com/session/sso?return_path=/

```

instead of

```plaintext
https://discourse.example.com/session/sso?return_path=%2F

```

That last bit, the `return_path`, is the path the user is being sent to in Discourse after login. If it’s `/` they’ll be sent to the forum homepage. For more on SSO url construction, see [WP Discourse Tips and Tricks](https://meta.discourse.org/t/wp-discourse-plugin-tips-and-tricks/50757).

---

<div class="post-metadata">

### Author: ![morevnaproject](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/morevnaproject/32/171168_2.png) [@morevnaproject](https://meta.discourse.org/u/morevnaproject)
#### Post date: [April 7, 2021, 2:59pm UTC](https://meta.discourse.org/t/wordpress-sso-and-patreon-login/156292/11 "2021-04-07T14:59:35Z")

</div>

> [@angus](#):
>
> there’s a decent long-tail risk here that your solution will break down

+1 yes, there is a risk! 🙂

> [@angus](#):
>
> I have some suggestions, but fair warning that this is going to get a bit technical

Woah, thank you so much for the detailed instructions! So, it makes sense to modify `[patreon_login_button]` shortcode to accept `final_redirect_uri` parameter, and make a PR to their github repo. Thanks again for taking your time to explain!
