# How to obtain the user\_id so I can issue a logout API call

**URL:** https://meta.discourse.org/t/how-to-obtain-the-user-id-so-i-can-issue-a-logout-api-call/102033
**Category:** SSO
**Created:** [14 בנובמבר,‏ 2018,‏ 2:55pm UTC](https://meta.discourse.org/t/how-to-obtain-the-user-id-so-i-can-issue-a-logout-api-call/102033 "2018-11-14T14:55:32Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![TeoWneD](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@TeoWneD](https://meta.discourse.org/u/TeoWneD)
#### Post date: [14 בנובמבר,‏ 2018,‏ 2:55pm UTC](https://meta.discourse.org/t/how-to-obtain-the-user-id-so-i-can-issue-a-logout-api-call/102033/1 "2018-11-14T14:55:33Z")

</div>

I searched into many differents posts about SSO logout. But i didn’t found my answer.  
We want to setup the SSO LOGOUT.  
You also have to know that we implemented SSO.

What is the query, that can return the UID, when i input username.

With that query we will be able to logout a user on the forum that just logout from the main website

This is the closest answer i found.

> [@DeanMarkTaylor](#):
>
> I believe you can make a server-side API call to:  
> ~~`http://discourse.example.com/admin/users/example_username/log_out`~~  
> `http://discourse.example.com/admin/users/{user_id}/log_out`   
> Where the `user_id` is a number.
> 
> This will logout all active discourse user sessions for `example_username` - obviously double check this works as expected for you.
> 
> The same as other Discourse API calls pass the “API Key” as needed:  
> `http://discourse.example.com/admin/api`

Can’t we just use sso,sig and token to identify ourself to the forum ? i mean by that that the main website already has those information, is there any way to use it to identify the user we want to logout

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [14 בנובמבר,‏ 2018,‏ 3:19pm UTC](https://meta.discourse.org/t/how-to-obtain-the-user-id-so-i-can-issue-a-logout-api-call/102033/2 "2018-11-14T15:19:01Z")

</div>

> [@TeoWneD](#):
>
> What is the query, that can return the UID, when i input username.

`GET https://example.com/u/USERNAME.json`

> [@TeoWneD](#):
>
> Can’t we just use sso,sig and token to identify ourself to the forum ? i mean by that that the main website already has those information, is there any way to use it to identify the user we want to logout

Since you implement SSO, you have the `external_id` of the user, so you can use:

`GET https://example.com/u/by-external/EXTERNAL_ID`

---

<div class="post-metadata">

### Author: ![TeoWneD](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@TeoWneD](https://meta.discourse.org/u/TeoWneD)
#### Post date: [14 בנובמבר,‏ 2018,‏ 3:30pm UTC](https://meta.discourse.org/t/how-to-obtain-the-user-id-so-i-can-issue-a-logout-api-call/102033/3 "2018-11-14T15:30:39Z")

</div>

Thanks great helping, It’s working for  
`https://example.com/u/USERNAME.json` Where i can find myself by replacing [example.com](http://example.com) (by the forum url) and USERNAME (by my username)

but for  
`https://example.com/u/by-external/EXTERNAL_ID`

When i tryed the same logic : Replacing [example.com](http://example.com) by the forum url and replacing EXTERNAL\_ID by : 1,2,3 and some random value.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [14 בנובמבר,‏ 2018,‏ 3:33pm UTC](https://meta.discourse.org/t/how-to-obtain-the-user-id-so-i-can-issue-a-logout-api-call/102033/4 "2018-11-14T15:33:49Z")

</div>

For the external you need the extension too, so

`GET https://example.com/u/by-external/EXTERNAL_ID.json`

---

<div class="post-metadata">

### Author: ![TeoWneD](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@TeoWneD](https://meta.discourse.org/u/TeoWneD)
#### Post date: [14 בנובמבר,‏ 2018,‏ 3:43pm UTC](https://meta.discourse.org/t/how-to-obtain-the-user-id-so-i-can-issue-a-logout-api-call/102033/5 "2018-11-14T15:43:28Z")

</div>

Big thanks to you Falco, your help has been VERY valuable, and as always your aswer very fast 😃

So the ‘How to obtain user\_id’ is now solved, but we are still trying to logout him

---

<div class="post-metadata">

### Author: ![TeoWneD](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@TeoWneD](https://meta.discourse.org/u/TeoWneD)
#### Post date: [14 בנובמבר,‏ 2018,‏ 4:06pm UTC](https://meta.discourse.org/t/how-to-obtain-the-user-id-so-i-can-issue-a-logout-api-call/102033/6 "2018-11-14T16:06:19Z")

</div>

What you gave us, is an url that only an admin can use to logout an user. is there any equivalent for a non admin person ?

Or can we make a querry as admin and make that querry not only leading to the logout page but actually disconnecting him

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [14 בנובמבר,‏ 2018,‏ 4:10pm UTC](https://meta.discourse.org/t/how-to-obtain-the-user-id-so-i-can-issue-a-logout-api-call/102033/7 "2018-11-14T16:10:56Z")

</div>

[https://meta.discourse.org/t/discourse-sso-logout/28509/10?u=falco](https://meta.discourse.org/t/discourse-sso-logout/28509/10?u=falco)

---

<div class="post-metadata">

### Author: ![TeoWneD](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@TeoWneD](https://meta.discourse.org/u/TeoWneD)
#### Post date: [14 בנובמבר,‏ 2018,‏ 4:15pm UTC](https://meta.discourse.org/t/how-to-obtain-the-user-id-so-i-can-issue-a-logout-api-call/102033/8 "2018-11-14T16:15:38Z")

</div>

Nice, Where in the querry should i supply the api key of an admin account?

Taking as example api key = XX and user UID = 50

`https://forum-website.com/admin/users/50/log_out`

Update:

I found a post talking about this is this the answer i was looking for ?

```plaintext
https://forum-website.com/admin/users/50/log_out?api_username=exampleAdmin&api_key=theKeyFromTheConsole

```

---

<div class="post-metadata">

### Author: ![TeoWneD](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@TeoWneD](https://meta.discourse.org/u/TeoWneD)
#### Post date: [14 בנובמבר,‏ 2018,‏ 4:38pm UTC](https://meta.discourse.org/t/how-to-obtain-the-user-id-so-i-can-issue-a-logout-api-call/102033/9 "2018-11-14T16:38:25Z")

</div>

So yeah it was the right syntax but :  
[https://forum](https://forum).[website].com/admin/users/[UID]/log\_out?api\_username=[username]&api\_key=[api\_key] It’s just leading to an admin page where i can manually disconnect the user.

i also tryed in incognito mode and the querry did’nt went threw it just said that i had been disconnected ( my admin account is’nt connected to the main website because of incognito mode) but as i puted the admin key in the querry it should work right ?

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [15 בנובמבר,‏ 2018,‏ 12:31am UTC](https://meta.discourse.org/t/how-to-obtain-the-user-id-so-i-can-issue-a-logout-api-call/102033/10 "2018-11-15T00:31:56Z")

</div>

that should be a POST, not a GET?

---

<div class="post-metadata">

### Author: ![TeoWneD](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@TeoWneD](https://meta.discourse.org/u/TeoWneD)
#### Post date: [15 בנובמבר,‏ 2018,‏ 9:30am UTC](https://meta.discourse.org/t/how-to-obtain-the-user-id-so-i-can-issue-a-logout-api-call/102033/11 "2018-11-15T09:30:35Z")

</div>

![test](https://global.discourse-cdn.com/meta/original/3X/3/c/3c28b482de7279ad9254f593f77ae07d9cbc9cf6.png)  
This is what we have as result when we try this querry via POST, in the terminale.

Edit: I modified a get querry sent from browser, into a post then it worked. Thanks i’ll keep you up. To know if i close the thread 🙂

---

<div class="post-metadata">

### Author: ![TeoWneD](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@TeoWneD](https://meta.discourse.org/u/TeoWneD)
#### Post date: [15 בנובמבר,‏ 2018,‏ 3:41pm UTC](https://meta.discourse.org/t/how-to-obtain-the-user-id-so-i-can-issue-a-logout-api-call/102033/12 "2018-11-15T15:41:55Z")

</div>

So with a GET querry modified and send again as a POST, to disconnect a user, we have the modale that open to : “say you’ve been disconnected click refresh”

So that is a good sign, but when we click refresh, it just start a infinite loop that lead to a “Bad redirection page”  
As you can see on that screenshot:

 ![multiple-redirections%20(2)](https://global.discourse-cdn.com/meta/original/3X/e/4/e46533fac2b81f6dcfb2e9dd96d75a3983e2d5e3.png)

Question is : What do we have to do to avoid the bad redirection, it looks like it’s because as the user is disconnected from main website and just been disconnected from forum, the forum keep asking to the main website if some one is connected. But when i tryed to fill the logout redirection, It’s changing nothing 😕

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [15 בנובמבר,‏ 2018,‏ 4:22pm UTC](https://meta.discourse.org/t/how-to-obtain-the-user-id-so-i-can-issue-a-logout-api-call/102033/13 "2018-11-15T16:22:58Z")

</div>

> [@TeoWneD](#):
>
> But when i tryed to fill the logout redirection, It’s changing nothing

The site setting `logout redirect` should point to somewhere no under auth, like your main site homepage or even [https://google.com](https://google.com).
