2011-02-02 73 views
11

似乎大部分WIF信息對於在整個應用程序中啓用聯合身份驗證非常有用。我有興趣使用API​​創建SAML身份驗證請求並接收/解釋SAML響應。使用WIF創建SAML身份驗證請求

我在SO Reading SAML Attributes from SAML Token上發現了以下帖子,這讓我在接收和解釋SAML響應方面朝着正確的方向前進。任何人都可以提供更多關於我如何使用API​​來創建SAML請求的信息嗎?

關於API的更多信息(閱讀材料,視頻等)將不勝感激。

回答

9

這裏有一個小例子形式our samples一個演示瞭如何編程創建一個(SAML)的請求安全令牌到STS:

private static SecurityToken GetSamlToken(string realm, string stsEndpoint, ClientCredentials clientCredentials) 
    { 
     using (var factory = new WSTrustChannelFactory(
      new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential), 
      new EndpointAddress(new Uri(stsEndpoint)))) 
     { 
      factory.Credentials.UserName.UserName = clientCredentials.UserName.UserName; 
      factory.Credentials.UserName.Password = clientCredentials.UserName.Password; 
      factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; 
      factory.TrustVersion = TrustVersion.WSTrust13; 

      WSTrustChannel channel = null; 

      try 
      { 
       var rst = new RequestSecurityToken 
           { 
            RequestType = WSTrust13Constants.RequestTypes.Issue, 
            AppliesTo = new EndpointAddress(realm), 
            KeyType = KeyTypes.Bearer, 
           }; 

       channel = (WSTrustChannel)factory.CreateChannel(); 

       return channel.Issue(rst); 
      } 
      finally 
      { 
       if (channel != null) 
       { 
        channel.Abort(); 
       } 

       factory.Abort(); 
      } 
     } 
+0

這是一個巨大的幫助。謝謝,歐金尼奧。 – 2013-02-11 15:49:08