# Clearing Okta session SID cookie from the browser

**URL:** <https://devforum.okta.com/t/clearing-okta-session-sid-cookie-from-the-browser/22316>\
**Category:** OAuth/OIDC\
**Created:** [November 2, 2022, 6:17pm UTC](https://devforum.okta.com/t/clearing-okta-session-sid-cookie-from-the-browser/22316 "2022-11-02T18:17:56Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![vdc305](https://avatars.discourse-cdn.com/v4/letter/v/e19b73/32.png) [@vdc305](https://devforum.okta.com/u/vdc305)\
**Post date:** [November 2, 2022, 6:17pm UTC](https://devforum.okta.com/t/clearing-okta-session-sid-cookie-from-the-browser/22316/1 "2022-11-02T18:17:56Z")

</div>

I have an SPA OIDC app configured in our custom tenant for auth code pkce flow. I get a session token from Okta’s authn url /api/v1/authn. I then use this session token to kick off the OIDC flow.

```auto
   this.oktaAuth.token.getWithoutPrompt({
      sessionToken : this.state.sessionToken
    }).then(response => {
      console.log("OKTA tokens from session token");
      this.setState({
        accessToken : response.tokens.accessToken.accessToken,
        refreshToken : response.tokens.refreshToken.refreshToken
      })
    })
    .catch(function(err) {
      console.log('err - getTokenWithoutPromptWithSessionToken: ' + err)
      console.log(err)

    });

```

I have the below code base to logout the user. The access and refresh tokens are revoked but not the Okta sid cookie. When the session token of a different identity gets passed in getWithoutPrompt, I am getting OIDC tokens associated to the prior user logged in. It seems like getWithoutPrompt is taking Okta sid cookie as a precedence then the session token.

```auto
oktaAuth.revokeAccessToken();
oktaAuth.revokeRefreshToken();

oktaAuth
	.closeSession()
	.then((response) => {
	     console.log('closeSession' + response);
	  })
	.catch((e) => {
			if (e.xhr && e.xhr.status === 429) {
					console.log('closeSessionIssue' + e.xhr);
			}
	});

```

Is signout() more suitable to revoke OIDC tokens and Okta sid cookie ?

---

<div class="post-metadata">

**Author:** ![okra-okta](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/okra-okta/32/2838_2.png) [@okra-okta](https://devforum.okta.com/u/okra-okta)\
**Post date:** [November 2, 2022, 6:40pm UTC](https://devforum.okta.com/t/clearing-okta-session-sid-cookie-from-the-browser/22316/2 "2022-11-02T18:40:19Z")

</div>

Yes, signOut() with default options will revoke the access token and refresh token for you.

> **[GitHub - okta/okta-auth-js: The official js wrapper around Okta's auth API](https://github.com/okta/okta-auth-js#signout)**
>
> The official js wrapper around Okta's auth API. Contribute to okta/okta-auth-js development by creating an account on GitHub.

It makes a request to the /logout endpoint which will also remove the Okta browser session.

> **[OpenID Connect & OAuth 2.0 API | Okta Developer](https://developer.okta.com/docs/reference/api/oidc/#logout)**
>
> Find information about the OAuth 2.0 and OpenID Connect endpoints that Okta exposes on its authorization servers.

---

<div class="post-metadata">

**Author:** ![vdc305](https://avatars.discourse-cdn.com/v4/letter/v/e19b73/32.png) [@vdc305](https://devforum.okta.com/u/vdc305)\
**Post date:** [November 2, 2022, 7:37pm UTC](https://devforum.okta.com/t/clearing-okta-session-sid-cookie-from-the-browser/22316/3 "2022-11-02T19:37:54Z")

</div>

So I have the below code base for signout(). It does delete the Okta sid cookie but not the Okta access token. When I call the introspect url oauth2/{{customAuthzServer}}/v1/introspect my access token is still active.

```auto
    this.oktaAuth.signOut({
      postLogoutRedirectUri: 'https://localhost.test.example.com:3000/login-ui/refresh'
    });

```

---

<div class="post-metadata">

**Author:** ![okra-okta](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/okra-okta/32/2838_2.png) [@okra-okta](https://devforum.okta.com/u/okra-okta)\
**Post date:** [November 2, 2022, 8:44pm UTC](https://devforum.okta.com/t/clearing-okta-session-sid-cookie-from-the-browser/22316/4 "2022-11-02T20:44:47Z")

</div>

If you inspect the network requests via the browser developer tools, are you able to see the `/revoke` requests?

> **[Inspect network activity - Chrome Developers](https://developer.chrome.com/docs/devtools/network/)**
>
> A tutorial on the most popular network-related features in Chrome DevTools.

---

<div class="post-metadata">

**Author:** ![vdc305](https://avatars.discourse-cdn.com/v4/letter/v/e19b73/32.png) [@vdc305](https://devforum.okta.com/u/vdc305)\
**Post date:** [November 2, 2022, 9:47pm UTC](https://devforum.okta.com/t/clearing-okta-session-sid-cookie-from-the-browser/22316/5 "2022-11-02T21:47:11Z")

</div>

No its not calling revoke. But its calling https://{customAuthzDomain}/api/v1/sessions/me, DELETE method.

Revoke would be the appropriate call based on the docs.

---

<div class="post-metadata">

**Author:** ![vdc305](https://avatars.discourse-cdn.com/v4/letter/v/e19b73/32.png) [@vdc305](https://devforum.okta.com/u/vdc305)\
**Post date:** [November 2, 2022, 11:42pm UTC](https://devforum.okta.com/t/clearing-okta-session-sid-cookie-from-the-browser/22316/6 "2022-11-02T23:42:06Z")

</div>

Also, if revoke and then logout is called, it deletes the sid and revokes the access and refresh token. In the logout url, it has the id\_token as per below. Is the id\_token picked from local token manager, or Okta knows about the id\_token based on Okta sid cookie ?

```auto
(https://{customOktaDomain}/oauth2/{authZServer}/v1/logout?id_token_hint={id_token}&post_logout_redirect_uri=https://localhost.example.com:3000/callback)

```

---

<div class="post-metadata">

**Author:** ![warren](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@warren](https://devforum.okta.com/u/warren)\
**Post date:** [November 3, 2022, 4:09am UTC](https://devforum.okta.com/t/clearing-okta-session-sid-cookie-from-the-browser/22316/7 "2022-11-03T04:09:55Z")

</div>

It is the id\_token from tokenManager which I believe defaults to localstorage.

---

<div class="post-metadata">

**Author:** ![vdc305](https://avatars.discourse-cdn.com/v4/letter/v/e19b73/32.png) [@vdc305](https://devforum.okta.com/u/vdc305)\
**Post date:** [November 3, 2022, 4:17am UTC](https://devforum.okta.com/t/clearing-okta-session-sid-cookie-from-the-browser/22316/8 "2022-11-03T04:17:50Z")

</div>

I have the tokenManager set to

```auto
tokenManager: {
			storage: sessionStorage, 
		},

```

---

<div class="post-metadata">

**Author:** ![vdc305](https://avatars.discourse-cdn.com/v4/letter/v/e19b73/32.png) [@vdc305](https://devforum.okta.com/u/vdc305)\
**Post date:** [November 3, 2022, 5:23am UTC](https://devforum.okta.com/t/clearing-okta-session-sid-cookie-from-the-browser/22316/9 "2022-11-03T05:23:30Z")

</div>

So under what situation does /revoke and /logout gets called as compared to DELETE method on sessions/me through sign out method in okta auth js Sdk?

---

<div class="post-metadata">

**Author:** ![okra-okta](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/okra-okta/32/2838_2.png) [@okra-okta](https://devforum.okta.com/u/okra-okta)\
**Post date:** [November 3, 2022, 4:39pm UTC](https://devforum.okta.com/t/clearing-okta-session-sid-cookie-from-the-browser/22316/10 "2022-11-03T16:39:04Z")

</div>

The DELETE call to /sessions/me is the fallback option when `/logout` can not be used, such as if tokens are not found in storage.

> <https://github.com/okta/okta-auth-js/blob/a57a689fedf4484d694865f7a0c04b14837f9bf3/lib/oidc/mixin/index.ts#L316-L319>

---

<div class="post-metadata">

**Author:** ![vdc305](https://avatars.discourse-cdn.com/v4/letter/v/e19b73/32.png) [@vdc305](https://devforum.okta.com/u/vdc305)\
**Post date:** [November 3, 2022, 4:49pm UTC](https://devforum.okta.com/t/clearing-okta-session-sid-cookie-from-the-browser/22316/11 "2022-11-03T16:49:13Z")

</div>

So can I call /logout directly from my javascript app and use it to revoke OIDC tokens or call /revoke endpoint directly from javascript with access token of the identity? Or is there any other way to revoke the tokens from my javascript ? Also, I tried `oktaAuth.revokeRefreshToken` and `oktaAuth.revokeAccessToken` it didnt work for me. In our SPA, when a user clicks logout, it goes to downstream service to delete additional company wide token and it redirects back to our UI logout page. I think when it redirects, the token manager is lost and hence `oktaAuth.revokeRefreshToken` and `oktaAuth.revokeAccessToken` dont work.

---

<div class="post-metadata">

**Author:** ![okra-okta](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/okra-okta/32/2838_2.png) [@okra-okta](https://devforum.okta.com/u/okra-okta)\
**Post date:** [November 3, 2022, 10:52pm UTC](https://devforum.okta.com/t/clearing-okta-session-sid-cookie-from-the-browser/22316/12 "2022-11-03T22:52:09Z")

</div>

You can call `/logout` manually but it won’t revoke the tokens, it would only clear your Okta browser session.

If you move `oktaAuth.revokeRefreshToken` and `oktaAuth.revokeAccessToken` before the the redirect occurs, does it still fail?

---

<div class="post-metadata">

**Author:** ![vdc305](https://avatars.discourse-cdn.com/v4/letter/v/e19b73/32.png) [@vdc305](https://devforum.okta.com/u/vdc305)\
**Post date:** [November 4, 2022, 12:47am UTC](https://devforum.okta.com/t/clearing-okta-session-sid-cookie-from-the-browser/22316/13 "2022-11-04T00:47:48Z")

</div>

Yes,it does fail.

So in my case once the OIDC flow is successful in our login SPA it redirects to another UI (lets say SPA Z)within our company. If the user wants to logout, it (SPA Z) calls our backend service to revoke the company wide SSO token and then the backend service redirects to login SPA /logout page. I think because it redirects back to login SPA app, we dont have TokenManager where the OIDC tokens are accessible.

So one solution I tried is, once the OIDC flow is successful, my login SPA app stores the access and refresh token object in local storage and when the login SPA is accessed for logout operation from another UI, it accesses the access and refresh token object from local storage and passes it in oktaAuth.signOut() method. Also, calling the signOut() deletes the Okta session (ie sid cookie).

```auto
oktaAuth.signOut({
        accessToken: JSON.parse(localStorage.getItem('accessToken')),
        refreshToken: JSON.parse(localStorage.getItem('refreshToken')),
        postLogoutRedirectUri: myDomain + '/loginUi/logout/',
});

OR another way to revoke access and refresh tokens

oktaAuth.revokeRefreshToken(refreshToken)
oktaAuth.revokeRefreshToken(accessToken)

```

Please do let me know if there is any other way

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [February 12, 2024, 10:18pm UTC](https://devforum.okta.com/t/clearing-okta-session-sid-cookie-from-the-browser/22316/14 "2024-02-12T22:18:09Z")

</div>

Closed on February 12, 2024, 10:18pm UTC


