IdentityServer4-注销后重定向到MVC客户端 [英] IdentityServer4 - Redirect to MVC client after Logout

查看:69
本文介绍了IdentityServer4-注销后重定向到MVC客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用IdenetityServer4,并在注销不起作用后重定向到MVC客户端.以下是我的MVC客户端控制器注销操作:

I am using IdenetityServer4 and Redirecting to MVC client after Logout is not working. Following is my MVC client controller Logout action:

public async Task Logout()
{
    await HttpContext.Authentication.SignOutAsync("Cookies");
    await HttpContext.Authentication.SignOutAsync("oidc");
}

以下是身份服务器4主机配置文件.

Following is identity server 4 Host config file.

public static IEnumerable<Client> GetClients()
{
    return new List<Client>
    {
        // other clients omitted...

        // OpenID Connect implicit flow client (MVC)
        new Client
        {
            ClientId = "mvc",
            ClientName = "MVC Client",
            AllowedGrantTypes = GrantTypes.Implicit,

            // where to redirect to after login
            RedirectUris = { "http://localhost:58422/signin-oidc" },

            // where to redirect to after logout
            PostLogoutRedirectUris = { "http://localhost:58422/signout-callback-oidc" },

            AllowedScopes = new List<string>
            {
                IdentityServerConstants.StandardScopes.OpenId,
                IdentityServerConstants.StandardScopes.Profile
            }
        }
    };
} 

我希望从IdentityServer注销后将用户重定向回MVC客户端.现在,用户必须单击下面图像中显示的链接才能重定向回MVC站点,但我认为用户应自动重定向回MVC客户端.

I want user to be redirect back to MVC client after getting Logged out from IdentityServer. Right now user has to click link show in below image to redirected back to MVC site but i think user should be automatically redirected back to MVC client.

推荐答案

您的Config.cs或MVC控制器没有问题.

There is no problem in your Config.cs or in the MVC controller.

转到您的IdentityServer4应用程序,然后在AccountController的Logout [HttpPost]方法中,进行以下更改:

Go to your IdentityServer4 Application then inside AccountController's Logout [HttpPost] method, do the following changes:

public async Task<IActionResult> Logout(LogoutViewModel model)
{
   ...    
  //return View("LoggedOut", vm);
  return Redirect(vm.PostLogoutRedirectUri);
}

这会将用户重定向回MVC应用程序(在您的情况下).

This will redirect the user back to MVC application (in your case).

有一个更好的方法可以做到这一点:您可以从AccountOptions.cs设置这些选项,如下所示:

There is a better way to do this: You can set these options from AccountOptions.cs as follows:

public static bool ShowLogoutPrompt = false;
public static bool AutomaticRedirectAfterSignOut = true;

这篇关于IdentityServer4-注销后重定向到MVC客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆