# Ajax Logout from the frontend application without javascript adapter

**URL:** <https://forum.keycloak.org/t/ajax-logout-from-the-frontend-application-without-javascript-adapter/3069>\
**Category:** Getting advice\
**Tags:** authentication, oidc\
**Created:** [June 1, 2020, 5:58pm UTC](https://forum.keycloak.org/t/ajax-logout-from-the-frontend-application-without-javascript-adapter/3069 "2020-06-01T17:58:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fmayoral](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/fmayoral/32/135_2.png) [@fmayoral](https://forum.keycloak.org/u/fmayoral)\
**Post date:** [June 1, 2020, 5:58pm UTC](https://forum.keycloak.org/t/ajax-logout-from-the-frontend-application-without-javascript-adapter/3069/1 "2020-06-01T17:58:49Z")

</div>

Hello everyone,  
I’m trying to get more control on the logout flow on the frontend. I am not using the javascript adapter.  
Currently I’m redirecting my users to the utility logout-redirect endpoint, however I want to control the user experience here and avoid doing redirects.  
I’ve tried the backchannel logout endpoint using a public client but I get a CORS error.  
The public client web origins is set to \*  
This is how the request looks:

```
HEADERS: 
  - Authorization: Bearer ACCESS_TOKEN
  - Content-Type: application/x-www-form-urlencoded

POST <BASE_URL>/auth/realms/REALM/protocol/openid-connect/logout?client_id=public&refresh_token=REFRESH_TOKEN

```

I’ve been struggling with the documentation to be honest and this is what I put together from multiple stackoverflow posts and old messages from the keycloak mail list.

Any hints on how this should be done?

_edit: clarified I’m not using js adapter_

---

<div class="post-metadata">

**Author:** ![zonaut](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/zonaut/32/666_2.png) [@zonaut](https://forum.keycloak.org/u/zonaut)\
**Post date:** [June 1, 2020, 6:45pm UTC](https://forum.keycloak.org/t/ajax-logout-from-the-frontend-application-without-javascript-adapter/3069/2 "2020-06-01T18:45:21Z")

</div>

> <https://github.com/keycloak/keycloak-documentation/blob/master/securing_apps/topics/oidc/javascript-adapter.adoc>

---

<div class="post-metadata">

**Author:** ![fmayoral](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/fmayoral/32/135_2.png) [@fmayoral](https://forum.keycloak.org/u/fmayoral)\
**Post date:** [June 2, 2020, 10:19am UTC](https://forum.keycloak.org/t/ajax-logout-from-the-frontend-application-without-javascript-adapter/3069/3 "2020-06-02T10:19:27Z")

</div>

Hi, I’ve read that one before but I’m not using the js adapters, I’ve updated my question to clarify that.  
I couldn’t find there how to do it other than redirecting to the logout endpoint.  
Thanks!

---

<div class="post-metadata">

**Author:** ![zonaut](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/zonaut/32/666_2.png) [@zonaut](https://forum.keycloak.org/u/zonaut)\
**Post date:** [June 2, 2020, 10:20am UTC](https://forum.keycloak.org/t/ajax-logout-from-the-frontend-application-without-javascript-adapter/3069/4 "2020-06-02T10:20:43Z")

</div>

You could look at the source code of the javascript adapter.

---

<div class="post-metadata">

**Author:** ![fmayoral](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/fmayoral/32/135_2.png) [@fmayoral](https://forum.keycloak.org/u/fmayoral)\
**Post date:** [June 2, 2020, 8:13pm UTC](https://forum.keycloak.org/t/ajax-logout-from-the-frontend-application-without-javascript-adapter/3069/5 "2020-06-02T20:13:15Z")

</div>

So I’ve been through the [adapter source code](https://github.com/keycloak/keycloak/blob/master/adapters/oidc/js/src/main/resources/keycloak.js) and it is not using a backchannel logout, it simply [replaces the window location with the logout url](https://github.com/keycloak/keycloak/blob/master/adapters/oidc/js/src/main/resources/keycloak.js#L1287-L1290) using the provided options, but thanks for the suggestion.

---

<div class="post-metadata">

**Author:** ![djuluka](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@djuluka](https://forum.keycloak.org/u/djuluka)\
**Post date:** [July 30, 2020, 12:14am UTC](https://forum.keycloak.org/t/ajax-logout-from-the-frontend-application-without-javascript-adapter/3069/6 "2020-07-30T00:14:29Z")

</div>

Hi @fmayoral this work for me  
`
const refresToken = localStorage.getItem(‘refresh_token’);
const headers = new HttpHeaders({ ‘Content-Type’: ‘application/x-www-form-urlencoded’ });
const body = new URLSearchParams();
body.set(‘client_id’, this.clientId);
body.set(‘refresh_token’, this.refresToken );`

`
```
return this.httpClient.post(this.apiUrlLogout, body.toString(), { headers}
  ).subscribe(response => {
    console.log(response);
});

```
`
