# Implement Log out button

**URL:** https://meta.discourse.org/t/implement-log-out-button/122321
**Category:** Development
**Created:** [July 8, 2019, 1:08pm UTC](https://meta.discourse.org/t/implement-log-out-button/122321 "2019-07-08T13:08:43Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Rahul\_Goswami](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rahul_goswami/32/139414_2.png) [@Rahul\_Goswami](https://meta.discourse.org/u/Rahul_Goswami)
#### Post date: [July 8, 2019, 1:08pm UTC](https://meta.discourse.org/t/implement-log-out-button/122321/1 "2019-07-08T13:08:43Z")

</div>

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

---

<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: [July 8, 2019, 5:06pm UTC](https://meta.discourse.org/t/implement-log-out-button/122321/2 "2019-07-08T17:06:20Z")

</div>

> [@Rahul\_Goswami](#):
>
> Login button will be in discourse, but logout option will be outside.

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: [wp-discourse/lib/sso-provider/discourse-sso.php at main · discourse/wp-discourse · GitHub](https://github.com/discourse/wp-discourse/blob/master/lib/sso-provider/discourse-sso.php#L222)

---

<div class="post-metadata">

### Author: ![Rahul\_Goswami](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rahul_goswami/32/139414_2.png) [@Rahul\_Goswami](https://meta.discourse.org/u/Rahul_Goswami)
#### Post date: [July 11, 2019, 6:30am UTC](https://meta.discourse.org/t/implement-log-out-button/122321/3 "2019-07-11T06:30:08Z")

</div>

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?

---

<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: [July 11, 2019, 7:06am UTC](https://meta.discourse.org/t/implement-log-out-button/122321/4 "2019-07-11T07:06:51Z")

</div>

> [@Rahul\_Goswami](#):
>
> i will need to enable sso for this functionality. right?

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

---

<div class="post-metadata">

### Author: ![Rahul\_Goswami](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rahul_goswami/32/139414_2.png) [@Rahul\_Goswami](https://meta.discourse.org/u/Rahul_Goswami)
#### Post date: [July 11, 2019, 7:24am UTC](https://meta.discourse.org/t/implement-log-out-button/122321/5 "2019-07-11T07:24:54Z")

</div>

![22%20PM](https://global.discourse-cdn.com/meta/original/3X/a/f/af7c75c24fe69ec7e9eea1e1511caaf380f59943.png)

I am getting 404 error. can you help me?

---

<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: [July 11, 2019, 7:44am UTC](https://meta.discourse.org/t/implement-log-out-button/122321/6 "2019-07-11T07:44:14Z")

</div>

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’

---

<div class="post-metadata">

### Author: ![Rahul\_Goswami](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rahul_goswami/32/139414_2.png) [@Rahul\_Goswami](https://meta.discourse.org/u/Rahul_Goswami)
#### Post date: [July 12, 2019, 4:54am UTC](https://meta.discourse.org/t/implement-log-out-button/122321/7 "2019-07-12T04:54:06Z")

</div>

Thank you. It worked.
