Search code examples
oauthopenididentityserver3

Redirecting to login after logout (Identity Server 3)


This is my first experience with Identity Server. How can I redirect to login page after logout from Identity Server?

Please, guide me in the right direction.


Solution

  • So this is kinda annoying,

    IDS doesn't support auto redirect.

    There's like 4 things you need to do

    So to get some kind of redirect on logout you have to add this:

    RedirectToIdentityProvider = n =>
            {
                if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.LogoutRequest)
                {
                    var idTokenHint = n.OwinContext.Authentication.User.FindFirst("id_token");
    
                    if (idTokenHint != null)
                    {
                                n.ProtocolMessage.IdTokenHint = idTokenHint.Value;
                    }
                }
    
                    return Task.FromResult(0);
            }
    

    to the client code

    then you need to add the post logout uri to the client setup

    THEN

    do this as well

    Request.GetOwinContext().Authentication.SignOut(new AuthenticationProperties
        {
            RedirectUri = "https://localhost:44306/"
        });
    

    And I think that's it

    I also added the LogoutUri to the client but I don't think that's necessary