# Create Plugin to Logout user via uid from SAML

**URL:** https://meta.discourse.org/t/create-plugin-to-logout-user-via-uid-from-saml/377116
**Category:** Development
**Tags:** saml
**Created:** [August 4, 2025, 12:11am UTC](https://meta.discourse.org/t/create-plugin-to-logout-user-via-uid-from-saml/377116 "2025-08-04T00:11:18Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![PortChange](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/portchange/32/316112_2.png) [@PortChange](https://meta.discourse.org/u/PortChange)
#### Post date: [August 4, 2025, 12:11am UTC](https://meta.discourse.org/t/create-plugin-to-logout-user-via-uid-from-saml/377116/1 "2025-08-04T00:11:19Z")

</div>

I use SAML groups to authenticate users to different categories. When the groups change, the user has to login. I want to automate this in my IDP. When groups changes, it uses the API to logout user

```plaintext
curl -X POST “https://mydiscourse.org/admin/users//log_out.json” -H “Content-Type: application/json” -H “Api-Key: XXXX” -H “Api-Username: Admin” -v

```

With API-Token only with log\_out right, this can be done very secure.

However IDP doesn’t have the numeric ID of user. It only has a unique number.

I already discovered how to logout user via console enter app and rails c

```plaintext
uaa = UserAssociatedAccount.find_by(provider_name: “saml”, provider_uid: “123456”)
user = uaa.user
user.user_auth_tokens.destroy_all

```

So my idea was to create a custom endpoint, with similiar usage

```plaintext
curl -X POST https://mydiscourse.org/custom/saml-logout/123456 -H “Api-Key: xxx” -H “Api-Username: Admin” -H “Accept: application/json”

```

This either just forwards received auth\_token to official API, probably safest method. ID can be obtained via user.id (see rest above)

Or it executes

```plaintext
uaa = UserAssociatedAccount.find_by(provider_name: “saml”, provider_uid: “123456”)
user = uaa.user
user.user_auth_tokens.destroy_all

```

Are there simple plugins where I can simply paste this very small piece of code into? I am no ruby programmer, but this is are so few lines of code. This should be feasible in a few minutes.

Thank you very much for your help.
