Identityserver4: How do I get the logoutid?

Created on 30 Mar 2017  路  7Comments  路  Source: IdentityServer/IdentityServer4

  • [x] I read and understood how to enable logging

Hello there,
I have a node application that is using IdSrv4 to authenticate users using OpenIdConnect. Everything works great. The only thing I have missing right now is that the logoutId does not get passed to my Idsrv from my application. The openid connect client that I am using for node says that I am on my own when it comes to logout. How and where is this available? The id_token does not have anything like this in it. Is one of the properties of the id_token being used as the logout id? I also see id_token_hint being passed. I am assuming these 2 fields are needed for a proper logout.

question

Most helpful comment

Docs have (finally) been written covering this topic: https://identityserver4.readthedocs.io/en/release/topics/signout.html

All 7 comments

The logoutId is an internal detail that stays within IdentityServer -- it won't ever be passed to your client apkplication. It allows the logout page at IdentityServer to know the correct context for achieving single signout.

The following bit of code from the samples gave me the impression that it needed to be passed in if I decide to call the AccountController.Logout action directly:

[HttpGet]
        public async Task<IActionResult> Logout(string logoutId)
        {
            var vm = await _account.BuildLogoutViewModelAsync(logoutId);
       ....

The following bit of code from the samples gave me the impression that it needed to be passed in if I decide to call the AccountController.Logout action directly:

Your client should be hitting thr end session endpoint, not the logout controller/page directly.

Docs have (finally) been written covering this topic: https://identityserver4.readthedocs.io/en/release/topics/signout.html

For core 2.1, add scaffolding files for Microsoft' Identity, in Logout.cshtml.cs, add namespaces of
using IdentityServer4.Services;
using IdentityServer4.Models;
using IdentityServer4.Events;
using Microsoft.AspNetCore.Authentication;
using IdentityServer4.Extensions;

And inject of
private readonly IIdentityServerInteractionService _interaction;
private readonly IEventService _events;

Change public void OnGet(){} to public async Task OnGet(string logoutId)

For me, just following codes

public async Task OnGet(string logoutId)
{
var logout = await _interaction.GetLogoutContextAsync(logoutId);
if (User?.Identity.IsAuthenticated == true)
{
// delete local authentication cookie
await HttpContext.SignOutAsync();

            await _signInManager.SignOutAsync();

            // raise the logout event
            await _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()));
        }
        return Redirect(logout?.PostLogoutRedirectUri);

    }

I had a similar issue and realize that this happens when you have not properly configured the PostLogoutRedirectUri in ClientPostLogoutRedirectUris table. In my case, I began experiencing it when I moved environment and didn't register the new environment's url.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings