# SSO Redirect Issues

**URL:** https://meta.discourse.org/t/sso-redirect-issues/216011
**Category:** WordPress
**Created:** [January 26, 2022, 12:23am UTC](https://meta.discourse.org/t/sso-redirect-issues/216011 "2022-01-26T00:23:29Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![dbwhite](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dbwhite/32/247431_2.png) [@dbwhite](https://meta.discourse.org/u/dbwhite)
#### Post date: [January 26, 2022, 12:23am UTC](https://meta.discourse.org/t/sso-redirect-issues/216011/1 "2022-01-26T00:23:30Z")

</div>

I am integrating Discourse with Wordpress via the [WP Discourse](https://github.com/discourse/wp-discourse) plugin and using Wordpress as the [Discourse Connect](https://meta.discourse.org/t/13045?silent=true) provider, however I’m running into an issue where an unauthenticated user visiting the discourse instance and clicking any button that requires a login will cause them to get stuck in an infinite redirect loop.

The desired behavior is: user clicks Discourse login button → user is redirected to Wordpress login page → user authenticates and is redirected back to the Discourse page they were on before. Currently there are no issues if a user is _already_ authenticated and visits the Discourse instance after being authenticated. This error shows up when an unauthenticated user visits the Discourse instance first.

The current behavior is: **user clicks a Discourse login button**  **→**  **user is directed to** https://[discourse-instance]/session/sso?return\_path=%2Ft%2F[discourse page user was on before]%2F16 **→ user is directed to** https://[wordpress-site]/?sso=[SSO token]%3D%3D&sig=[Signature token] **→ user is directed to** https://[wordpress-site]/?sso=[SSO token]%3D%3D&sig=[Signature token]&redirect\_to=%2F%3Fsso%[SSO token]%253D%253D%26sig%3D[Signature token] **→ and the cycle continues recursively until the browser throws a “too many redirects” error**

I haven’t been able to find a thread with a fix for this, the closest one is

> [@SSO redirect loop](https://meta.discourse.org/t/sso-redirect-loop/117898):
>
> Hey there, we’re using Discourse [v2.3.0.beta2 +130] with SSO. For a few months now (sorry that I can’t pinpoint the exact update that caused the issue) collegues are reporting SSO redirect loops (followed by 429 errors which is ok) when clicking on discourse links in webmail clients. This only happens, if one is already logged in. We can reproduce in Firefox and Chrome on Windows and Linux. Steps to reproduce: When logged out of discourse (all cookies cleaned etc) Click on a Disourse link in…

but we have SSL enabled everywhere and this issue happens across all browsers. Any suggestions on how to fix this issue?

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [January 26, 2022, 12:40am UTC](https://meta.discourse.org/t/sso-redirect-issues/216011/2 "2022-01-26T00:40:02Z")

</div>

Chrome 97 shipped with [a bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1286367) related to cookie handling during redirects, which is known to break [DiscourseConnect](https://meta.discourse.org/t/13045?silent=true) in some circumstances. While we wait for Google to roll out a fix, we’ve added a workaround to Discourse. Upgrading your Discourse site to the latest version should solve the problem. Can you give that a try and let us know if it works?

(Workaround was added in [this commit](https://github.com/discourse/discourse/commit/2278c7f82dd8e7f24dc6dc66bc6fea02e598c6d0))

---

<div class="post-metadata">

### Author: ![dbwhite](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dbwhite/32/247431_2.png) [@dbwhite](https://meta.discourse.org/u/dbwhite)
#### Post date: [January 27, 2022, 8:53pm UTC](https://meta.discourse.org/t/sso-redirect-issues/216011/3 "2022-01-27T20:53:40Z")

</div>

Thanks for the reply, I just checked to make sure we are on the latest version but unfortunately the error is still there. We are hosting our forum with Discourse so it should be updating itself regularly. The error is still the same as it was before, is there anything else I should try? Are there settings within Discourse hosting that could be causing this?

---

<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: [January 28, 2022, 12:16am UTC](https://meta.discourse.org/t/sso-redirect-issues/216011/4 "2022-01-28T00:16:03Z")

</div>

Hey @dbwhite, could you please

1. enable “Verbose [DiscourseConnect](https://meta.discourse.org/t/13045?silent=true) Logs” in the [WP Discourse](https://github.com/discourse/wp-discourse) “[DiscourseConnect](https://meta.discourse.org/t/13045?silent=true)” settings
2. re-create the issue
3. go to “Logs” in [WP Discourse](https://github.com/discourse/wp-discourse) and “Download” them

Then PM me the logs and I’ll take a closer look at what’s happening. Note that the logs do not contain any personally identifying information or secrets.

---

<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: [January 28, 2022, 1:33am UTC](https://meta.discourse.org/t/sso-redirect-issues/216011/5 "2022-01-28T01:33:45Z")

</div>

@angus, @dbwhite a possible cause of the issue could be if the WordPress site is using Woocommerce. Woocommerce adds a login redirect that can cause issues with [DiscourseConnect](https://meta.discourse.org/t/13045?silent=true). Those redirects can be overwritten by either installing and activating [GitHub - scossar/wp-discourse-woocommerce-support: Integrates the wp-discourse plugin with WooCommerce · GitHub](https://github.com/scossar/wp-discourse-woocommerce-support), or by adding the code snippets that are given in that plugin’s readme to the site’s theme.

The redirect issue that is being described here seems similar to what I’ve seen with other Woocommerce sites in the past. In those cases, it’s been resolved by installing the WordPress plugin that I linked to.

If this is the cause of the issue, I wonder if we should look into adding Woocommerce support directly to the [WP Discourse](https://github.com/discourse/wp-discourse) plugin.

---

<div class="post-metadata">

### Author: ![jord8on](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jord8on/32/166809_2.png) [@jord8on](https://meta.discourse.org/u/jord8on)
#### Post date: [February 22, 2022, 6:55pm UTC](https://meta.discourse.org/t/sso-redirect-issues/216011/6 "2022-02-22T18:55:18Z")

</div>

> [@simon](#):
>
> I wonder if we should look into adding Woocommerce support directly to the [WP Discourse](https://github.com/discourse/wp-discourse) plugin.

That would be extremely helpful.

I’m not having the exact issue that the OP has described but I am hitting a wall with redirecting our users back to the place where they were, in the discourse forums, after login 😞

---

<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: [February 22, 2022, 7:24pm UTC](https://meta.discourse.org/t/sso-redirect-issues/216011/7 "2022-02-22T19:24:35Z")

</div>

> [@jord8on](#):
>
> I am hitting a wall with redirecting our users back to the place where they were, in the discourse forums, after login

Does installing and activating the [WP Discourse](https://github.com/discourse/wp-discourse) WooCommerce Support plugin resolve the issue for you?

---

<div class="post-metadata">

### Author: ![dbwhite](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dbwhite/32/247431_2.png) [@dbwhite](https://meta.discourse.org/u/dbwhite)
#### Post date: [March 4, 2022, 12:56am UTC](https://meta.discourse.org/t/sso-redirect-issues/216011/8 "2022-03-04T00:56:03Z")

</div>

Just wanted to post an update here, it turns out one of the plugins we were using was interfering with the return value of the `wp_login_url()` Wordpress function. Once that plugin was removed everything worked as expected!

---

<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: [August 25, 2022, 6:53am UTC](https://meta.discourse.org/t/sso-redirect-issues/216011/9 "2022-08-25T06:53:41Z")

</div>

A post was split to a new topic: [Rails error when using DiscourseConnect and Wordpress](https://meta.discourse.org/t/rails-error-when-using-discourseconnect-and-wordpress/237133)
