asp.net-mvcasp.net-corelogoutduende-identity-server

How to Retrieve id_token for End Session Endpoint in Duende IdentityServer v6.2.3 and Asp.Net Core 6.0 MVC?


I have a Asp.Net Core 6.0 MVC app, which authenticates with our Duende IdentityServer (v6.2.3). When I want to logout of identityserver, it states that you must call the end session endpoint. One of the params is id_token, which is needed so it can determine the client. The thing is, I don't get an id_token when authenticating, so how can I get this? Appreciate any help.

The client is configured as 'authorization_code' grant type in identityserver, and OpenIdConnect ResponseType option is set to "code". I've tried changing this to 'code id_token', but this results in an error.


Solution

  • I didn't realise that the id_token was contained within the authentication ticket in the cookie. I just added this bit of code to retrieve it.

    var properties = (await _contextAccessor.HttpContext?.AuthenticateAsync()!).Properties?.Items!;
    
    if (properties != null && properties.TryGetValue(".Token.id_token", out var token))
       return token;
    
    return null;