IdentityServer4 PostLogoutRedirectUri

后端 未结 5 848
无人共我
无人共我 2021-01-02 05:01

I am confused about how this is used.

Most examples I\'ve seen have it given as \"/signout-callback-oidc\". That seems to indicate that it uses OIDC middleware in t

5条回答
  •  隐瞒了意图╮
    2021-01-02 05:55

    I want to share how I solved problem with null PostLogoutRedirectUri value. I always had null PostLogoutRedirectUri value in logout context until I added SignInScheme value on mvc client side. These settings of authentication on MVC client side works for me:

    var authenticationBuilder = services.AddAuthentication(options =>
    {
        options.DefaultScheme = "Cookies";
        options.DefaultChallengeScheme = "oidc";
    });
    
    authenticationBuilder.AddCookie(options =>
    {
        options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
        options.Cookie.Name = "identity_server_mvc";
    });
    
    authenticationBuilder.AddOpenIdConnect("oidc", options =>
    {
        options.Authority = "{IDENTITY_SERVER_URL}";
        options.ClientId = "mvc";
        options.SaveTokens = true;
        options.SignInScheme = "Cookies";
    });
    

    You also need to make sure that you have added the PostLogoutRedirectUri value to the client configuration on the Identity Server side:

    new Client
    {
        ClientId = "mvc",
        AllowedGrantTypes = GrantTypes.Implicit,
    
        RedirectUris           = { "{CLIENT_URL}/signin-oidc" },
        PostLogoutRedirectUris = { "{CLIENT_URL}/signout-callback-oidc" },
    
        AllowedScopes =
        {
            IdentityServerConstants.StandardScopes.OpenId,
            IdentityServerConstants.StandardScopes.Profile
        }
    }
    

    One last but important point, because of this I had null logoutId value on Identity Server side. To initiate Logout process you must first call SignOut("Cookies", "oidc") on mvc client side. Example endpoint in my HomeController:

    public IActionResult Logout()
    {
        return SignOut("Cookies", "oidc");
    }
    

    Good luck!

提交回复
热议问题