2016-10-12 38 views
0

我正在將舊的現有Web窗體站點配置爲多租戶環境。一個要求是能夠與多個客戶端ADFS集成。 我跟着this post已經成功實現了一個支持多個ADFS的MVC應用程序。不過,我仍然遇到一個問題, ,這是不能與MVC應用程序重現。在我的Web表單網站中,只有第一個註冊的ADFS提供程序成功。第二個總是 在認證並返回到我的網站後發生SignatureVerificationFailedException(異常發生在我身邊)。 這是無論我在OWIN啓動配置中使用app.Map(...)還是app.Use(...)。
我試圖將我的網站轉換爲Web應用程序,但結果相同。我想這與WEB FORMS中處理請求的方式有關,它與MVC不同。

我應該以某種不同的方式處理中間件映射嗎?
我錯過了什麼?
或者這是根本不可能的......ASP.NET Web Forms站點 - 使用OWIN與多個ADFS集成KATANA

這裏是我的OWIN啓動配置:

app.Properties["Microsoft.Owin.Security.Constants.DefaultSignInAsAuthenticationType"] = Config.ExternalAuthentication.Cookie; 
app.UseCookieAuthentication(new CookieAuthenticationOptions 
{ 
    AuthenticationType = Config.ExternalAuthentication.Cookie, 
    AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Passive 
}); 

string wreply = Config.ExternalAuthentication.Wreply; 
string wtrealm = Config.ExternalAuthentication.Wtrealm; 

List<Company> adfsCompanies = BL.GetCompaniesWithADFS(); 
app.Map("/Public/Login.aspx", configuration => 
{ 
    foreach (Company company in adfsCompanies) 
    { 
     //configure middleware 
     var middleware = new WsFederationAuthenticationOptions() 
     { 
      MetadataAddress = company.ADFSMetadataUrl, 
      AuthenticationType = company.TenantName, 
      Caption = company.Name, 
      Wreply = wreply, 
      Wtrealm = wtrealm, 
      BackchannelCertificateValidator = null 
     };  

     //add to pipeline 
     configuration.UseWsFederationAuthentication(middleware); 
    } 
}); 

這裏是我的挑戰要求:

context.GetOwinContext().Authentication.Challenge(
    new AuthenticationProperties { RedirectUri = callbackUrl }, 
    provider); 
response.StatusCode = 401; 
response.End(); 

不管我做什麼,只第一個註冊的ADFS中間件成功了,不管是哪一個。我也嘗試將中間件附加到不同的流水線階段,但沒有成功。

在此先感謝您的幫助!

回答

1

對於多個wsfed中間件,每個應設置唯一的WsFederationAuthenticationOptions.CallbackPath,例如, 「/ WS1」。你還需要將這個值包含在wreply中。

+0

非常感謝@Tratcher。你的回答並沒有給出完整的解決方案,但它使我朝着正確的方向前進。爲了讓問題保持簡潔清晰,我會給出更多的答案 – Vladislav

0

我只是給一些更多的細節被@Tratcher建議的解決方案,以保持清潔問題和簡單的:

1)According to MSDNCallbackPath如果沒有設置從Wreply計算;

2)在爲每個供應商區分Wreply後,結果不夠,因爲出現了其他問題。然後我發現(使用我的MVC工作樣本),此外WtrealmWreply應該具有相同的值;

3)在ASP.NET Web Forms中爲不同的提供者設置不同的URL並不那麼容易。假的網址無效。使用URL重寫 - 也。
最直接的解決方案是爲每個提供者使用不同的回調頁面(例如ExternalLoginFirstADFS.aspx,ExternalLoginSecondADFS.aspx,...)。這一點,雖然做工精細,是不是最好的,所以我決定在Application_Start事件在Global.asax中配置路由爲每個提供這樣的:

void Application_Start(object sender, EventArgs e) 
{ 
    ... 
    RegisterRoutes(System.Web.Routing.RouteTable.Routes); 
} 

public static void RegisterRoutes(System.Web.Routing.RouteCollection routes) 
{ 
    List<Organization> adfsCompanies = OrgElementEntity.GetCompaniesWithADFS(); 
    foreach(Organization company in adfsCompanies) 
    { 
     routes.MapPageRoute("", 
      String.Format("Public/ExternalLogin{0}.aspx", company.TenantName), 
      "~/Public/ExternalLogin.aspx"); 
    } 
} 

而且,事實證明,沒有必要過於使用app.Map(...)OwinStartup。通過app.UseWsFederationAuthentication(...)添加每個中間件似乎都很好!

相關問題