2011-02-02 41 views
11

Dường như hầu hết thông tin WIF đều hữu ích khi bật xác thực liên kết trên toàn bộ ứng dụng. Tôi quan tâm đến việc sử dụng API để tạo các yêu cầu xác thực SAML và nhận/giải thích các phản hồi SAML.Tạo yêu cầu xác thực SAML bằng WIF

Tôi tìm thấy bài đăng sau đây trên SO Reading SAML Attributes from SAML Token giúp tôi đi đúng hướng liên quan đến việc nhận và giải thích các câu trả lời SAML. Bất cứ ai có thể cho tôi biết thêm thông tin về cách tôi có thể sử dụng API để tạo yêu cầu SAML không?

Mọi thông tin khác (đọc tài liệu, video, v.v.) trên API nói chung sẽ được đánh giá cao.

Trả lời

9

Dưới đây là một chút hình thức ví dụ một trong our samples cho thấy làm thế nào để programatically tạo một yêu cầu cho một (SAML) Mã bảo mật cho một 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

Đây là một trợ giúp lớn. Cảm ơn, Eugenio. –

+4

Tôi không tin rằng điều này tạo ra một SAML 'AuthnRequest' ở tất cả. Dường như nó tạo ra một WSTrust 'RequestSecurityToken'. – atoumey

Các vấn đề liên quan