How to redirect user to client app after logging out from identity server?

后端 未结 1 939
执笔经年
执笔经年 2021-01-23 00:58

I want to redirect user to the same client after he logged out from that client. So if i have lets say 5 clients on one identity server, i want users to be able to log out from

1条回答
  •  别那么骄傲
    2021-01-23 01:36

    You are not supposed to set the uri manually. Actually the default logout method from the IdentityServer samples works fine.

    When you try the 3_ImplicitFlowAuthentication sample project, you'll see PostLogoutRedirectUri is not null and the redirection works (but not automatically).

    The reason why PostLogoutRedirectUri is null in your case is probably because the id_token is not preserved. In MvcClient.Startup make sure you add this line:

    options.SaveTokens = true;
    

    That will preserve the tokens in a cookie.

    In order to automatically redirect back to the client, make a few adjustments to the sample code. In IdentityServer AccountOptions set

    AutomaticRedirectAfterSignOut = true;
    

    In the AccountController.Logout method add the following lines:

    if (vm.AutomaticRedirectAfterSignOut && 
                   !string.IsNullOrWhiteSpace(vm.PostLogoutRedirectUri))
        return Redirect(vm.PostLogoutRedirectUri);
    

    Just before the last line:

    return View("LoggedOut", vm);
    

    When you run the sample again you should see that the user is now automatically returned to the client after logout.

    0 讨论(0)
提交回复
热议问题