# Logout from OIDC web app

**URL:** <https://devforum.okta.com/t/logout-from-oidc-web-app/1911>\
**Category:** OAuth/OIDC\
**Tags:** spring, java\
**Created:** [June 6, 2018, 4:14am UTC](https://devforum.okta.com/t/logout-from-oidc-web-app/1911 "2018-06-06T04:14:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![marc](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@marc](https://devforum.okta.com/u/marc)\
**Post date:** [June 6, 2018, 4:14am UTC](https://devforum.okta.com/t/logout-from-oidc-web-app/1911/1 "2018-06-06T04:14:36Z")

</div>

I am trying to implement logout feature in my spring-boot - oidc based web app. When I look at okta forum, I was able to see two recommendations (from below links) to delete the token from the okta server and other one is to delete the session.

below is the code which i am using in my spring app…

@Override  
protected void configure(HttpSecurity http) throws Exception {  
http.authorizeRequests()  
.anyRequest().authenticated().antMatchers(“logOutSuccessful”).permitAll()  
.and()  
.oauth2Login().loginPage("/customOAuth2Login\_Okta").permitAll()  
.and()  
.logout()  
.deleteCookies()  
.invalidateHttpSession(true)  
.logoutSuccessUrl("/logOutSuccessful")  
.logoutRequestMatcher(new AntPathRequestMatcher("/logoutMe")).permitAll();  
}

when I am using the above code, my cookies are not getting deleted and even when i implement custom logoutHandler to delete the session by making Delete call on [https://domainName/api/v1/sessions/me](https://domainName/api/v1/sessions/me), its not even working…  
its redirecting me to the /logOutSucccessful url and still I can see the cookies in my browser…

ref urls: [OpenID Connect & OAuth 2.0 API | Okta Developer](https://developer.okta.com/docs/api/resources/oidc#logout)  
[Sessions | Okta Developer](https://developer.okta.com/docs/api/resources/sessions)

Need help on the correct way to implement the logout for an oidc based web app in spring…  
thanks for ur help…

---

<div class="post-metadata">

**Author:** ![bdemers](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/bdemers/32/23_2.png) [@bdemers](https://devforum.okta.com/u/bdemers)\
**Post date:** [June 6, 2018, 2:04pm UTC](https://devforum.okta.com/t/logout-from-oidc-web-app/1911/2 "2018-06-06T14:04:28Z")

</div>

This is what Spring Security does [out of the box](https://docs.spring.io/spring-security/site/docs/5.0.5.RELEASE/reference/htmlsingle/#jc-logout):

- Invalidating the HTTP Session
- Cleaning up any RememberMe authentication that was configured
- Clearing the SecurityContextHolder
- Redirect to /login?logout

You will likely end up with a cookie at the end of this, but it _should_ be a different session.

Can you confirm your Spring Session is removed?

---

<div class="post-metadata">

**Author:** ![marc](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@marc](https://devforum.okta.com/u/marc)\
**Post date:** [June 6, 2018, 4:38pm UTC](https://devforum.okta.com/t/logout-from-oidc-web-app/1911/3 "2018-06-06T16:38:30Z")

</div>

thanks for your reply…  
I see like even after logout, for the next request, its not taking me to okta screen for authentication

---

<div class="post-metadata">

**Author:** ![bdemers](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/bdemers/32/23_2.png) [@bdemers](https://devforum.okta.com/u/bdemers)\
**Post date:** [June 6, 2018, 5:38pm UTC](https://devforum.okta.com/t/logout-from-oidc-web-app/1911/4 "2018-06-06T17:38:08Z")

</div>

Assuming you are redirecting to an Okta domain to login (and you already have an SSO session with Okta) you may get bounced back into your application without realizing it.

The easiest way to see if this is happening is to turn on developer tools and make sure “Preserve log” is enable.

Another way to tell is if your application has a different session id

---

<div class="post-metadata">

**Author:** ![marc](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@marc](https://devforum.okta.com/u/marc)\
**Post date:** [June 6, 2018, 8:05pm UTC](https://devforum.okta.com/t/logout-from-oidc-web-app/1911/5 "2018-06-06T20:05:21Z")

</div>

i was tracing the network log and came to that conclusion that the I still have the session, even though i log out…  
but when I implemented the following code, with our explicitly defining .deleteCookies() and invalidateHttpSession(true), I was able to see the call is going to okta for oAuth login again…

@Override  
protected void configure(HttpSecurity http) throws Exception {  
http.authorizeRequests()  
.anyRequest().authenticated()  
.and()  
.oauth2Login().loginPage("/customOAuth2Login\_Okta").permitAll()  
.and()  
.logout()  
.logoutRequestMatcher(new AntPathRequestMatcher("/perfomLogOut")).permitAll()  
.logoutSuccessUrl(“[https://mydomain/login/default](https://mydomain/login/default)”);  
//.addLogoutHandler(openIdLogoutHandler)  
}

thanks for looking into it

---

<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:** [January 12, 2024, 10:25pm UTC](https://devforum.okta.com/t/logout-from-oidc-web-app/1911/6 "2024-01-12T22:25:06Z")

</div>

Closed on January 12, 2024, 10:25pm UTC


