2 questions about WP Discourse

Is there any way to make an SSO link redirect to an URL with an anchor? I’m using Wordpress as a SSO client.

http://example.com/?discourse_sso=1&redirect_to=http://example.com/welcome#anchor
will redirect to
http://example.com/welcome#anchor?sso=fddsgsfzqefefsdfs or something like that… So that’s not working.

Other question: is it possible to automatically log out from Wordpress when we log out from Discourse (still using Wordpress as an SSO client), the same way as Discourse disconnects automatically when logging out from Wordpress when using Wordpress as an SSO provider?

What are You trying to achieve? there may be a different way to implement that.

There is a forum thread about it here

The solution is:

2 Likes

Try URL encoding the redirect parameter:

http://example.com/welcome#anchor becomes http%3A%2F%2Fexample.com%2Fwelcome%23anchor

Hello and thanks you for your replies.

When a user is on a Wordpress post page, I’ve added a button “log in to post a comment” to the bottom of the comments. If the user clicks this button, I’d like them to be redirected at the bottom of the comments (via an anchor) after they successfully log in.

Thank you for the logout reply!

Unfortunately, I’ve already tried it with no success…

Another question: is it possible to automatically log in Wordpress when logging in Discourse?

In my development environment, this works if I do not urlencode the redirect_to parameter. Whether or not this works may depend on your WordPress site’s server configuration.

It’s theoretically possible, but would require a Discourse plugin. I’m not sure that it would be worth the trouble. Adding a WordPress SSO login link to your forum should take care of most cases.

If you want to automatically create WordPress users when they are created on Discourse, a Discourse plugin could be written that posts to the WordPress REST API users/ route.

1 Like

After a few tests it appears that redirections with an anchor from WP works only if the user is already logged on Discourse.

Works in this case : WP not logged in -> Discourse already logged in -> logs user to WP
And not in this one : WP not logged in -> Discourse not logged in -> user logs in Discourse -> logs user to WP

But that doesn’t matter much after all.

Thank you for your replies. :slight_smile: