Reputation: 581
I have implemented backchannel logout and the URL is calling for all clients but it is not signout from all clients
Scenario
LogOut code
public async Task<IActionResult> Logout()
{
Console.WriteLine("** MVC2 logout " + DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"));
var client = _httpClientFactory.CreateClient("IDPClient");
var discoveryDocumentResponse = await client.GetDiscoveryDocumentAsync();
if (discoveryDocumentResponse.IsError)
{
throw new Exception(discoveryDocumentResponse.Error);
}
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
await HttpContext.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme);
return Redirect(discoveryDocumentResponse.EndSessionEndpoint);
}
BackChannel Logout code
[HttpPost]
[AllowAnonymous]
public async Task<IActionResult> BackChannelLogout(string token)
{
Console.WriteLine("*********************** MVC1 --> BackChannelLogout " + DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"));
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
await HttpContext.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme);
return NoContent();
}
I want to achieve, if logout from the Clients it , it should redirect to the identity server for login
Upvotes: 0
Views: 1325
Reputation: 19961
Your logout code in your client should not return anything, because that will interfere with the respose that SignOutAsync creates internally for you.
A sample logout can look like this:
/// <summary>
/// Do the logout
/// </summary>
/// <returns></returns>
[HttpPost]
[ValidateAntiForgeryToken]
public async Task Logout()
{
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
await HttpContext.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme);
//Important, this method should never return anything.
}
Upvotes: 1