Duende Identity server - Get PostLogoutRedirectUri after logging out through my client app

890 views Asked by At

I am building an Identity server with the Duende Identity server software package.

The IdentityServer is .Net 6, and the client application is ASP.NET 4.6.2, which could complicate things.

In my Client app I have the following configuration:

`   app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
    {
    ClientId = "SomeId",
    Authority = "https://localhost:5001",
    RedirectUri = "https://localhost:5002",
    ClientSecret = "SomeSecret",
    ResponseType = "Code",
    Scope = "SomeScopes,
    PostLogoutRedirectUri = "https://localhost:5002/some-custom-path",

    SignInAsAuthenticationType = "Cookies",
    UseTokenLifetime = false,
            
    RedeemCode = true,
    SaveTokens = true,
    Notifications = new OpenIdConnectAuthenticationNotifications
    {
        SecurityTokenValidated = async context =>
        {
            var identity = context.AuthenticationTicket.Identity;
            var claims = identity.Claims;
            await Task.Yield();
        }
    }
});`

Assuming the OpenID configuration is correct (we can connect both apps together and login and logout through its login and logout pages), we cannot seem to get the PostLogoutRedirectUri in the LogoutContext:

`    var context = await _interaction.GetLogoutContextAsync(LogoutId);`

The context contains a couple properties which I expected to be filled, which are:

  1. ClientId
  2. ClientName
  3. PostLogoutRedirectUri

Somehow these values are null in my context. Could anyone explain why this is the case here?

We tried to pass the postLogoutRedirectUri through the RedirectToIdentityProvider in the client application, which also resulted in a null-result.

We have searched the internet, but most solutions that we come across are for .NET Core, which does not fit our client application.

We also tried the solution in the following post: How to redirect user to client app after logging out from identity server? , which also didn't work on our end.

UPDATE: Add logout method in client:

HttpCookie userCookie = new HttpCookie("UserCookie", "");
        userCookie.Expires = DateTime.Now.AddYears(-1);
        Response.Cookies.Add(userCookie);

        HttpContext.GetOwinContext().Authentication.SignOut(
                OpenIdConnectAuthenticationDefaults.AuthenticationType,
                CookieAuthenticationDefaults.AuthenticationType);

        return null;
1

There are 1 answers

0
RITURAJ POKHRIYAL On

@Bryan please check if you have added your client appliactions PostLogoutUri which is https://localhost:5002/some-custom-path in the PostLogoutRedirectUris of the client in Identity Server where you registered the client.

You have to add your client applications postlogouturl in your client in Identity server.

Eg:

var interactiveClient = new Client
{
    ClientId = "interactive",

    AllowedGrantTypes = GrantTypes.Code,
    AllowOfflineAccess = true,
    ClientSecrets = { new Secret("secret".Sha256()) },
    
    RedirectUris =           { "http://localhost:21402/signin-oidc" },
    PostLogoutRedirectUris = { "https://localhost:5002/some-custom-path" },
    FrontChannelLogoutUri =    "http://localhost:21402/signout-oidc",

    AllowedScopes = 
    {
        IdentityServerConstants.StandardScopes.OpenId,
        IdentityServerConstants.StandardScopes.Profile,
        IdentityServerConstants.StandardScopes.Email,

        "api1", "api2.read_only"
    },
};