Any idea why a simple logout request isn't working? No errors, it just doesn't logout the current user.
This is a simple c# controller that inherits from ControllerBase.
// /MyEditBar/logout/
public IActionResult Logout()
{
var context = _httpContextAccessor.HttpContext;
if (context != null)
{
var cookieOptions = _cookieOptionsSnapshot.Get(Umbraco.Cms.Core.Constants.Security.BackOfficeAuthenticationType);
var backOfficeCookie = context.Request.Cookies[cookieOptions.Cookie.Name!];
var unprotected = cookieOptions.TicketDataFormat.Unprotect(backOfficeCookie!);
var currentUser = unprotected?.Principal.GetUmbracoIdentity() ?? new ClaimsIdentity();
if (currentUser?.IsAuthenticated == true)
{
var userId = currentUser.GetUserId
();
_userService.ClearLoginSessions(userId);
return Content("Success");
}
}
return Content("Not Logged In");
}