# Log out all users via API

**URL:** https://meta.discourse.org/t/log-out-all-users-via-api/75851
**Category:** Feature
**Created:** [December 11, 2017, 11:25pm UTC](https://meta.discourse.org/t/log-out-all-users-via-api/75851 "2017-12-11T23:25:55Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![typeoneerror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/typeoneerror/32/80817_2.png) [@typeoneerror](https://meta.discourse.org/u/typeoneerror)
#### Post date: [December 11, 2017, 11:25pm UTC](https://meta.discourse.org/t/log-out-all-users-via-api/75851/1 "2017-12-11T23:25:55Z")

</div>

I’ve built a Discourse integration for our product that allows SSO with our product to a Discourse install. When a user is signed out on our app, I’m doing an API-backed POST via the [`log_out`](https://github.com/discourse/discourse_api/blob/master/lib/discourse_api/api/users.rb#L56) API. Is there a way to log _all_ users out or change settings remotely? If our user disconnects the Discourse integration, I’d love to nullify their custom SSO settings and sign out all users without having to do 100s of POST requests.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [December 11, 2017, 11:51pm UTC](https://meta.discourse.org/t/log-out-all-users-via-api/75851/2 "2017-12-11T23:51:41Z")

</div>

You would need a plugin here with a custom http endpoint

---

<div class="post-metadata">

### Author: ![typeoneerror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/typeoneerror/32/80817_2.png) [@typeoneerror](https://meta.discourse.org/u/typeoneerror)
#### Post date: [December 11, 2017, 11:53pm UTC](https://meta.discourse.org/t/log-out-all-users-via-api/75851/3 "2017-12-11T23:53:02Z")

</div>

Noted.

Is there a log out all users in the admin interface so I could document how to do this for customers who can’t install a plugin?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [December 11, 2017, 11:55pm UTC](https://meta.discourse.org/t/log-out-all-users-via-api/75851/4 "2017-12-11T23:55:27Z")

</div>

To log out every user on the system you would nuke all rows from the user auth tokens table

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [December 12, 2017, 8:54am UTC](https://meta.discourse.org/t/log-out-all-users-via-api/75851/5 "2017-12-12T08:54:19Z")

</div>

I’ve documented Rails code that (in addition to doing other things) logs out all users and sends them the usual notification that there were logged out here, in case this helps you:

> [@Re-purposing a Discourse installation for a yearly event](https://meta.discourse.org/t/re-purposing-a-discourse-installation-for-a-yearly-event/34670/17):
>
> Another year has passed, and we followed the same procedure. This time, we used actual Ruby scripts instead of my crazy API-based approach – maybe this is useful to someone else: Log out and deactivate (almost) all users: protected\_users = ["system", "codinghorror"] # do not process these users # get all users that should be logged out affected\_users = User.all.select { |u| !(protected\_users.include? u.username) } affected\_users.each { |u| u.admin = false u.moderator = false …

---

<div class="post-metadata">

### Author: ![typeoneerror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/typeoneerror/32/80817_2.png) [@typeoneerror](https://meta.discourse.org/u/typeoneerror)
#### Post date: [December 12, 2017, 4:45pm UTC](https://meta.discourse.org/t/log-out-all-users-via-api/75851/6 "2017-12-12T16:45:36Z")

</div>

This is great, thanks, Felix.
