# Discourse (as provider) + WP SSO nonce error

**URL:** <https://meta.discourse.org/t/discourse-as-provider-wp-sso-nonce-error/117113>\
**Category:** WordPress\
**Created:** [May 7, 2019, 7:48pm UTC](https://meta.discourse.org/t/discourse-as-provider-wp-sso-nonce-error/117113 "2019-05-07T19:48:12Z")\
**Posts on this page:** 14\
**Page:** 1

## AI-generated summary

[Sami_Syed](/t/-/117113/1) reports an "expired nonce" error when logging into WordPress via Discourse SSO, despite being successfully logged into Discourse. The issue appeared after one successful attempt and persists even in incognito mode. [simon](/t/-/117113/2) confirms the issue and investigates, ruling out MySQL version (5.7.25-28) as the cause. He suspects caching is the culprit — specifically, cached login links for non-logged-in users — and confirms this by manually appending a random string to the `discourse_sso` parameter, which allows login to succeed [simon](/t/-/117113/9). [Sami_Syed](/t/-/117113/8) had already tried adding nonce-refresh code to `functions.php`, but it failed due to page caching. [simon](/t/-/117113/11) suggests disabling object caching as a temporary fix. Further testing on WP Engine reveals that default caching doesn’t always trigger the issue, but page caching may be disabled by default on new sites. [simon](/t/-/117113/15) resolves the issue by creating a custom login page, requesting WP Engine to disable caching for it, and adding code to generate a fresh nonce on each login attempt. He also suspects Cloudflare may be involved if used. [Sami_Syed](/t/-/117113/13) follows up for updates, and [simon](/t/-/117113/14) asks for Cloudflare configuration details to further diagnose.

<div class="post-metadata">

**Author:** ![Sami\_Syed](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sami_syed/32/93193_2.png) [@Sami\_Syed](https://meta.discourse.org/u/Sami_Syed)\
**Post date:** [May 7, 2019, 7:48pm UTC](https://meta.discourse.org/t/discourse-as-provider-wp-sso-nonce-error/117113/1 "2019-05-07T19:48:12Z")

</div>

Hey guys,

I have my discourse setup as a provider and wordpress as the client.

And for some reason when I try to login to wordpress I get the error “expired nonce” and it reditects me to /wp-admin login screen. However, when I go back onto discourse, I am actully logged in.

The weird this is, the first time I tried it, it worked perfectly but now it isn’t anymore. I even tried on an incognito window.

So I assume this may be a problem with Wordpress and not discourse.

In specific the way I set it up?  
In order to get a menu option for users to log in/sign up, I did inspect element on the “Log in with discourse” shortcode. I then took the link that was in there and created menu links, as shown below:  
 ![Capture](https://global.discourse-cdn.com/meta/original/3X/c/a/cadb95b1c3d834973bfccbe853f97b9cc5d62cc3.jpeg)  
I don’t think this itself is an issue because even the “Log in with discourse” shortcode gives me the same error.

If you would like to test it out to see what the issue it, I created a test user.  
URL: [projectvanlife.com](http://projectvanlife.com)  
Username: bizness  
Password: test123456  
You will find the option to login via SSO at the top left of the screen (only visible on desktop atm)

Please help me find a solution to this problem. Thanks in advance!

---

<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:** [May 7, 2019, 9:47pm UTC](https://meta.discourse.org/t/discourse-as-provider-wp-sso-nonce-error/117113/2 "2019-05-07T21:47:33Z")

</div>

> [@Sami\_Syed](#):
>
> The weird this is, the first time I tried it, it worked perfectly but now it isn’t anymore.

Have you made any changes to your WordPress site since it stopped working?

Do you know what version of MySQL is being used for your WordPress site? The SSO client functionality requires at least MySQL version 5.6.5.

---

<div class="post-metadata">

**Author:** ![Sami\_Syed](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sami_syed/32/93193_2.png) [@Sami\_Syed](https://meta.discourse.org/u/Sami_Syed)\
**Post date:** [May 7, 2019, 10:06pm UTC](https://meta.discourse.org/t/discourse-as-provider-wp-sso-nonce-error/117113/3 "2019-05-07T22:06:46Z")

</div>

> [@simon](#):
>
> Have you made any changes to your WordPress site since it stopped working?

It only worked once, and then I tried it again right after (without making any changes) and it gave me the error.

Have you tried it yourself using the test account?

> [@simon](#):
>
> Do you know what version of MySQL is being used for your WordPress site? The SSO client functionality requires at least MySQL version 5.6.5.

Not sure but I will find out right now

---

<div class="post-metadata">

**Author:** ![Sami\_Syed](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sami_syed/32/93193_2.png) [@Sami\_Syed](https://meta.discourse.org/u/Sami_Syed)\
**Post date:** [May 7, 2019, 10:34pm UTC](https://meta.discourse.org/t/discourse-as-provider-wp-sso-nonce-error/117113/4 "2019-05-07T22:34:08Z")

</div>

> [@simon](#):
>
> MySQL version

Looks like the Mysql version is Ver 14.14 Distrib 5.7.25-28.

---

<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:** [May 7, 2019, 10:36pm UTC](https://meta.discourse.org/t/discourse-as-provider-wp-sso-nonce-error/117113/5 "2019-05-07T22:36:13Z")

</div>

> [@Sami\_Syed](#):
>
> Have you tried it yourself using the test account?

Yes, I tried it out and got the same error that you are getting. I’ll look into this some more.

> [@Sami\_Syed](#):
>
> Looks like the Mysql version is Ver 14.14 Distrib 5.7.25-28.

Thanks for checking. That makes it easier to debug what’s going on.

---

<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:** [May 8, 2019, 2:23am UTC](https://meta.discourse.org/t/discourse-as-provider-wp-sso-nonce-error/117113/7 "2019-05-08T02:23:01Z")

</div>

> [@Sami\_Syed](#):
>
> It only worked once, and then I tried it again right after (without making any changes) and it gave me the error.

There’s a good chance that what is happening on your site is related to the nonce being cached. Could you have a look at [Wordpress SSO Expired nonce - #15 by simon](https://meta.discourse.org/t/wordpress-sso-expired-nonce/105159/15)?

If you are able to add the code from that post to your theme, can you let me know what the results are?

---

<div class="post-metadata">

**Author:** ![Sami\_Syed](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sami_syed/32/93193_2.png) [@Sami\_Syed](https://meta.discourse.org/u/Sami_Syed)\
**Post date:** [May 8, 2019, 3:20am UTC](https://meta.discourse.org/t/discourse-as-provider-wp-sso-nonce-error/117113/8 "2019-05-08T03:20:08Z")

</div>

I’ve already tried that.

In fact that code is currently inside of my themes functions.php file

Despite it being there I am still getting this error

---

<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:** [May 8, 2019, 4:50pm UTC](https://meta.discourse.org/t/discourse-as-provider-wp-sso-nonce-error/117113/9 "2019-05-08T16:50:00Z")

</div>

> [@Sami\_Syed](#):
>
> I’ve already tried that.

Thanks for trying it. The reason the code you have added is failing to update the cached nonce is because the page the login link is displayed on is also cached for non-logged in users. This means that the same string is appended to the login link on every page load.

I was able to login successfully to your site through Discourse by copying your login link’s URL and then appending a new random string to the `discourse_sso` parameter. I’ll try to come up with a proper fix for this.

---

<div class="post-metadata">

**Author:** ![Sami\_Syed](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sami_syed/32/93193_2.png) [@Sami\_Syed](https://meta.discourse.org/u/Sami_Syed)\
**Post date:** [May 8, 2019, 7:57pm UTC](https://meta.discourse.org/t/discourse-as-provider-wp-sso-nonce-error/117113/10 "2019-05-08T19:57:38Z")

</div>

> [@simon](#):
>
> I was able to login successfully to your site through Discourse by copying your login link’s URL and then appending a new random string to the `discourse_sso` parameter. I’ll try to come up with a proper fix for this.

I see what you mean. So for now do I just sit tight, or is there a temporary fix for users?

> [@simon](#):
>
> The reason the code you have added is failing to update the cached nonce is because the page the login link is displayed on is also cached for non-logged in users

Is there any way to make it so it’s not cached?

Thank you btw for helping me out with this. Much appreciated!

---

<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:** [May 8, 2019, 8:06pm UTC](https://meta.discourse.org/t/discourse-as-provider-wp-sso-nonce-error/117113/11 "2019-05-08T20:06:44Z")

</div>

> [@Sami\_Syed](#):
>
> Is there any way to make it so it’s not cached?

The caching is either being done by a caching plugin that you have installed on your site, or by your hosting provider. Disabling Object Caching for your site would be a good temporary solution.

I’m working on a proper fix for this now.

---

<div class="post-metadata">

**Author:** ![Sami\_Syed](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sami_syed/32/93193_2.png) [@Sami\_Syed](https://meta.discourse.org/u/Sami_Syed)\
**Post date:** [May 8, 2019, 8:09pm UTC](https://meta.discourse.org/t/discourse-as-provider-wp-sso-nonce-error/117113/12 "2019-05-08T20:09:09Z")

</div>

Alright thanks, looking forward to seeing what you come up with!

---

<div class="post-metadata">

**Author:** ![Sami\_Syed](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sami_syed/32/93193_2.png) [@Sami\_Syed](https://meta.discourse.org/u/Sami_Syed)\
**Post date:** [May 9, 2019, 4:13pm UTC](https://meta.discourse.org/t/discourse-as-provider-wp-sso-nonce-error/117113/13 "2019-05-09T16:13:02Z")

</div>

HAve you got any updates yet?

---

<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:** [May 15, 2019, 6:57pm UTC](https://meta.discourse.org/t/discourse-as-provider-wp-sso-nonce-error/117113/14 "2019-05-15T18:57:10Z")

</div>

I have tested this with a new site hosted on WP Engine. I believe your site is hosted there as well. With the default WP Engine caching enabled, I’m not having any problems logging into the site via Discourse.

Are you using Cloudflare? If so, I suspect the problem is related to what is described here: [https://meta.discourse.org/t/wordpress-sso-expired-nonce/105159/14](https://meta.discourse.org/t/wordpress-sso-expired-nonce/105159/14). Would you be able to give some details about how you have Cloudflare configured?

---

<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:** [May 24, 2019, 8:29pm UTC](https://meta.discourse.org/t/discourse-as-provider-wp-sso-nonce-error/117113/15 "2019-05-24T20:29:28Z")

</div>

> [@simon](#):
>
> With the default WP Engine caching enabled, I’m not having any problems logging into the site via Discourse.

It seems that when a site is created on WP Engine, page caching may not be initially setup. I revisited my site today and got the ‘expired nonce’ error when attempting to login with the `[discourse_sso_client]` shortcode from my site’s homepage.

To fix the issue, I created a custom login page and then contacted WP Engine to ask them to disable caching for my login page. I also included the following code in my theme’s `functions.php` file. This code ensures that a fresh nonce will be generated for the login attempt.

```php
add_filter('wpdc_sso_client_query', 'wpdc_custom_sso_client_query' );
function wpdc_custom_sso_client_query() {
    return wp_generate_password( 12, false );
}

```
