Implement Log out button

Hi,

I want to implement a logout button outside Discourse. The button should have same functionality like -

  1. It should logout users from all device
  2. A referesh button which will take user to some url.

Note: Login button will be in discourse, but logout option will be outside.

Any article/dicussion/help will be highly appreciated.

Thank you

You can log users out through the Discourse API by making an authenticated POST request to /admin/users/<user_id>/log_out. You need to replace <user_id> with the user’s Discourse user ID.

You can see this implemented in the Discourse WordPress plugin here: https://github.com/discourse/wp-discourse/blob/master/lib/sso-provider/discourse-sso.php#L222

7 Likes

Hi @simon , i will need to enable sso for this functionality. right? and if yes what are the things i will need to fill/enable for enabling sso just for logout?

No, enabling SSO is not required for the call to /admin/users/<user_id>/log_out to work.

I am getting 404 error. can you help me?

You need to set both the Api-Key and Api-Username headers. If you are using the All Users API Key, the Api-Username header should probably be set to ‘system’

6 Likes

Thank you. It worked.

2 Likes