2013-03-13 61 views
3

簡單的單點登錄問題單點登錄隨着ACS通過多個應用程序

我有兩個MVC4應用:

**1**- http://localhost/BikeShop  

    ACS Relying Party: 

- Name: **BikeShop** 
- Return Url: **http://localhost/BikeShop** 
- Token Format: **SAML 2.0** 


**2**- http://localhost/BikePartsShop 

    ACS Relying Party: 

- Name: **BikePartsShop** 
- Return Url: **http://localhost/BikePartsShop** 
- Token Format: **SAML 2.0** 

的情景我有

我訪問BikeShop和ACS Login Page出現,我選擇我的身份。

我現在可以做的東西在BikeShop

然後我訪問BikePartsShop和ACS登錄頁面,我可以選擇我的身份。


的情景我必須

我訪問BikeShop和ACS登錄頁面呈現和我選擇了我的身份。

我現在可以做的東西在BikeShop

然後我訪問BikePartsShop和ACS授權在BikeShop使用,無需進一步的用戶干預的相同身份 。


有沒有人實施過這種情況?

最好的問候,謝謝!

+0

BikeShop和BikePartsShop應該是一個RP而不是兩個?一個RP可以支持多個回覆地址,這將允許在兩個地方使用相同的令牌。 – 2013-03-13 21:08:37

+0

ACS如何實現? ACS中繼方只能有一個回覆地址configure(返回URL) – TheBigCheese 2013-03-15 17:08:52

+0

如果不是這樣,ACS支持根據需要配置儘可能多的回覆地址。我會發佈一個答案。 – 2013-03-15 18:30:02

回答

1

您可以使用ACS管理服務爲同一個依賴方配置多個回覆地址。有關如何添加RP的詳細信息,請參閱this link。從鏈接的代碼示例,如下注冊更多的地址:

RelyingParty relyingParty = new RelyingParty() 
{ 
    Name = "BikeShop", 
    AsymmetricTokenEncryptionRequired = false, 
    TokenType = "SAML_2_0", 
    TokenLifetime = 3600 
}; 

svc.AddToRelyingParties(relyingParty); 

RelyingPartyAddress realm = new RelyingPartyAddress() 
{ 
    Address = "http://localhost/", 
    EndpointType = "Realm" 
}; 

RelyingPartyAddress replyAddress1 = new RelyingPartyAddress() 
{ 
    Address = "http://localhost/BikeShop", 
    EndpointType = "Reply" 
}; 

RelyingPartyAddress replyAddress2 = new RelyingPartyAddress() 
{ 
    Address = "http://localhost/BikePartsShop", 
    EndpointType = "Reply" 
}; 

svc.AddRelatedObject(relyingParty, "RelyingPartyAddresses", realmAddress); 
svc.AddRelatedObject(relyingParty, "RelyingPartyAddresses", replyAddress1); 
svc.AddRelatedObject(relyingParty, "RelyingPartyAddresses", replyAddress2); 

svc.SaveChanges(SaveChangesOptions.Batch); 
+0

我會嘗試這個解決方案。謝謝! – TheBigCheese 2013-03-16 00:48:23

+0

此解決方案不適用於我的方案。 – TheBigCheese 2013-03-18 12:21:44

+0

執行所有代碼並能夠成功部署並運行後,創建了ACS依賴方,添加了身份提供程序,並配置了回覆地址。所有規則對兩個應用都正確執行。索賠正在正確構建。但是,如果沒有顯示ACS的「登錄」屏幕,在您選擇要使用的身份提供商的網站中,我仍然無法更改網站。 – TheBigCheese 2013-03-18 14:29:07

0

嘗試這個代碼,以幫助你前進到一個特定的身份提供者,如果你能弄清楚如何記住哪個身份提供者,他們最後一次使用。最後一次登錄應該被存儲,以便你自動回到你的應用程序。

public IdentityProvider GetIdentityProvider(string identityProviderName, string realm , string audienceUri) 
     { 
      // acs config parameters 
      string acsNamespace = ConfigurationManager.AppSettings["ida:Namespace"]; 
      realm = realm ?? Uri.EscapeDataString(ConfigurationManager.AppSettings["ida:Realm"]); 
      audienceUri = audienceUri ?? ConfigurationManager.AppSettings["ida:AudienceUri"]; 

      string returnPath = Uri.EscapeDataString("/home/index"); 
      var newReplyTo = 
       Uri.EscapeDataString(audienceUri.Replace(new Uri(audienceUri).Authority, 
        HttpContext.Current.Request.Url.Authority)); 
      // retrieve current identity providers 
      string idpDiscoveryUrl = string.Format("{0}v2/metadata/IdentityProviders.js?protocol=wsfederation&realm={1}&reply_to={2}&context=rm%3d0%26id%3dpassive%26ru%3d{3}&request_id=&version=1.0", acsNamespace, realm, newReplyTo, returnPath); 
      string response = null; 
      using (var client = new WebClient()) { 
      response = client.DownloadString(idpDiscoveryUrl);  
      } 

      List<IdentityProvider> identityProviders = JsonConvert.DeserializeObject<List<IdentityProvider>>(response); 
      // lookup provider for tenant 
      var identityProvider = identityProviders.Where(i => i.Name == identityProviderName).FirstOrDefault() ?? new IdentityProvider(); 

      return identityProvider; 
     } 
相關問題