Logout POST Request

Hi, I’ve recently been trying to create a single sign out system where I can log off on my website and it will automatically log the user off of their Discourse account as well. According to this website https://meta.discourse.org/t/discourseconnect-official-single-sign-on-for-discourse-sso/13045

Logging off users
You can use the POST admin endpoint /admin/users/{USER_ID}/log_out to log out any user in the system if needed.
To configure the endpoint Discourse redirects to on logout search for the logout redirect setting. If no URL has been set here you will be redirected back to the URL configured in discourse connect url .

I’ve created an API key to accomplish this, then made a POST request using https://reqbin.com/ to https://MY_DISCOURSE_DOMAIN/admin/users/USER_ID/log_out?api_key=XXXXXXXXXXXXXXXXXXXXXX&api_username=system
For my API key, I allowed system to be my user. If anyone could give me some guidance as to why this isn’t working, it would be greatly appreciated.

2 Likes

I’ve figured it out, so I will leave the link to the other forum here so others like me can have an easier time trying to implement this. It turns out that the other topics that suggest you put your api_key and api_username in the URL were invalidated about half a year ago. The new way to make the POST request is to follow the steps in the following forum.

In my case, I logged someone out by making the following curl request:

curl -X POST "https://DICOURSE-WEBSITE/admin/users/USER-ID/log_out" -H "Content-Type: multipart/form-data;" -H "Api-Key: INSERT-API-KEY" -H "Api-Username: INSERT-API-USERNAME"
6 Likes

Glad to hear you got it working!

Would you mind sharing links to the outdated topics, so that we can update/delete them?

2 Likes

Here is the outdated topic https://meta.discourse.org/t/how-to-obtain-the-user-id-so-i-can-issue-a-logout-api-call/102033/5. The other topics only seemed outdated because I had just read this one.

3 Likes

Thanks, I’ve added a couple of notes to that topic

3 Likes

This topic was automatically closed after 23 hours. New replies are no longer allowed.