2017-01-16 48 views
4

鑑於IdentitySever3重定向URL多個域

一個ASP MVC網站IIS。該網站用身份識別服務器以非正式流程對用戶進行身份驗證。

有多個域被攻擊。所以該網站是從不同的域名。例如

  • foo.com
  • foo.de
  • foo.fr

問題

現在,當我配置我的網站,我必須設置重定向URL,但它取決於關於用戶來自哪裏。但是,由於此配置是在應用程序啓動時完成的,因此根據傳入的請求我無法改變。

這是什麼推薦的方法?

public static void Configure(IAppBuilder app) 
{ 
     app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions 
      { 
       AuthenticationType = "oidc", 
       Authority = ConfigurationManager.AppSettings["authority"], 
       ClientId = "BlsFrontend", 
       RedirectUri = "http://foo.de", //how to get this dynamically? 
       ResponseType = "id_token token", 
       SignInAsAuthenticationType = "Cookies", 
       Scope = "openid profile", 

有一件事我在考慮是使用RedirectToIdentityProvider通知和adpot在請求重定向。我測試過它,它適用於我的情況,但這是否是一種有效/好的方法?

RedirectToIdentityProvider = n => 
{ 
    if (!string.IsNullOrWhiteSpace(n.ProtocolMessage.RedirectUri)) 
    { 
     n.ProtocolMessage.RedirectUri = n.Request.Scheme + "://" + n.Request.Host.ToString(); //How to make it clean !? 
    } 
} 
+0

這是正確的方式,RedirectUri由權威機構驗證。 –

回答

0

我張貼這是因爲我沒有發現任何其他的解決問題和其他一些人也採用了這種解決方案

的解決方案是正確的之前設置重定向URL根據請求的解決方案我們被重定向到身份服務器。爲此,我使用RedirectToIdentityProvider通知

RedirectToIdentityProvider = n => 
{ 

    if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.Authentication && 
     !string.IsNullOrWhiteSpace(n.ProtocolMessage.RedirectUri)) 
    { 
     n.ProtocolMessage.RedirectUri = n.Request.Scheme + "://" + n.Request.Host.ToString(); //How to make it clean !? 
    } 
}