2017-04-06 88 views
5

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

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

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

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客户端。

enter image description here

+1

份额错误,请和其他日志。 – Lutando

回答

5

。在你的Config.cs或MVC控制器没有问题。

转到您的IdentityServer4应用程序,然后里面的AccountController的注销[HttpPost]的方法,做了以下修改:

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

这将用户重定向回MVC应用程序(你的情况)。

有一个更好的方式来做到这一点: 可以进行如下设置从AccountOptions.cs这些选项:

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

我与@Sandeep具有相同的客户端配置,包括PostLogoutRedirectUris,但是当我以调试模式启动项目时,可以看到vm.PostLogoutRedirectUri为空。任何想法为什么? – CodeEngine

+0

需要更多解释。您在调试时是否试图从客户端注销?因为vm.PostLogoutRedirectUri将在从任何配置的客户端收到注销请求时设置。 – Akhilesh