2017-04-06 28 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