Asp.Net OpenID Logout Issues

Hello,

I’m trying to implement logout in my Asp.Net application. My code is based on quick start from here:
https://github.com/oktadeveloper/okta-aspnet-mvc-example/tree/master/OktaAspNetExample

When I initiate Okta logout I’m geting next issues:

  1. Okta API /logout endpoint does not support CORS so browser blocks any requests.
  2. After adding CORS plugin to Chrome I’m getting “Not found: Resource not found” expection in response (I can see it in browser console). However I can delete current session using RESTED plugin (DELETE https://dev-522077.oktapreview.com/api/v1/sessions/me).

Please help, thanks in advance.

Normal OpenID Connect Flow does not work because CORS is not supported.
To delete current session I have to use /api/v1/sessions/me endpoint (CORS supported).
Client side script looks like:
$.ajax({
url: ‘https://dev-{yourId}.oktapreview.com/api/v1/sessions/me’,
type: ‘DELETE’,
xhrFields: { withCredentials: true },
success: function(result) {
window.location.reload();
}
});

The problem was that cookies were not attached to the request. “xhrFields: { withCredentials: true }” solved the issue.

Assuming your application is set up like the example you linked to, you should log out by calling:

HttpContext.GetOwinContext().Authentication.SignOut(
    CookieAuthenticationDefaults.AuthenticationType, 
    OpenIdConnectAuthenticationDefaults.AuthenticationType);

This does two things:

  • Delete the aspnet cookie that is keeping track of the local session
  • Redirects to Okta to delete the user’s session in Okta

Okta will redirect back to your app on the PostLogoutRedirectUri you set in Startup.cs.

Hi Nate,

I do logout by calling:
HttpContext.GetOwinContext().Authentication.SignOut(
CookieAuthenticationDefaults.AuthenticationType,
OpenIdConnectAuthenticationDefaults.AuthenticationType);

But this is not related to the issues described in the first message (especially CORS).

Regards,
Yury

@Urik Sorry for the delay. Did you get this working?

OIDC logout from aspnetcore shouldn’t need CORS. If you get CORS errors doing a logout (unless you are working with a single-page app), something usually isn’t configured right.

Hi Nate,

I know this post is a bit old but I have an asp.net web site and have configured it following the web forms example.

However, when I log out, the cookie seems to be removed but when I’m redirected to okta, I receive a “bad result…invalid Id token” error.

Option 1) seems to remove the cookie but does nothing else.

Context.GetOwinContext().Authentication.SignOut(CookieAuthenticationDefaults.AuthenticationType);

Option 2)

does redirect to okta but presents the invalid id token error

Context.GetOwinContext().Authentication.SignOut( CookieAuthenticationDefaults.AuthenticationType, OpenIdConnectAuthenticationDefaults.AuthenticationType);

Any help would be greatly appreciated!

I’m assuming that either:

The token isn’t getting returned from okta due to potentially not requesting it correctly in startup.cs

It’s not getting saved due to an error or omission within startup.cs

It’s not getting attached and sent to okta during the logout redirect