2012-06-29 63 views
1

我有一個有效的SAML 2令牌從我的應用國際開發署獲取XML命名空間的錯誤,而讀令牌的SAML2

當我嘗試使用WIF代碼如下讀它,我得到以下錯誤:

Cannot read the token from the 'Response' element with the 'urn:oasis:names:tc:SAML:2.0:protocol' namespace for BinarySecretSecurityToken, with a '' ValueType. If this element is expected to be valid, ensure that security is configured to consume tokens with the name, namespace and value type specified.

這裏是我與顯示評論它失敗

 string certPath = @"G:\Projects\myAPp\SAMLHandlingTests\bin\Debug\SSO.cer"; 
     X509Certificate2 cert = new X509Certificate2(certPath); 
     //X509Certificate2 cert = new X509Certificate2(certPath, "LetMeIn!"); 


     // Open the SAML 
     string samlPath = @"G:\Projects\myAPp\SAMLHandlingTests\bin\Debug\SAML.xml"; 

     string samlRaw = File.OpenText(samlPath).ReadToEnd(); 

     XmlReader rdr = XmlReader.Create(samlPath); 

     List<System.IdentityModel.Tokens.SecurityToken> tokens = new List<System.IdentityModel.Tokens.SecurityToken>(); 

     var token = new X509SecurityToken(cert); 
     tokens.Add(token); 

     SecurityTokenResolver resolver = 
      SecurityTokenResolver.CreateDefaultSecurityTokenResolver(
      new System.Collections.ObjectModel.ReadOnlyCollection<SecurityToken>(tokens), true); 

     //Fails on next line! 
     SecurityToken securityToken = System.ServiceModel.Security.WSSecurityTokenSerializer.DefaultInstance.ReadToken(rdr, resolver); 

     SamlSecurityToken deserializedSaml = securityToken as SamlSecurityToken; 

的問題是一個XML命名空間異常,但我不知道如何「確保秒使用的代碼urity被配置爲消耗具有指定名稱,名稱空間和值類型的標記'

請問有人能指出我正確的方向嗎?

回答

2

好吧,我發現這個問題,它是用加密的斷言SAML響應其沒有類型定義如下:

的SAML收到如下:

<saml:EncryptedAssertion> 

時,它應該是

<saml:EncryptedAssertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"> 

這當然可以在我的代碼中解決這個問題,但潛在的問題是System.Xml和WIF不會讓我沒有完全v alid xml。

我希望這可以幫助一路上的人。

+0

我有同樣的例外,但我的是SAML 1.0:'任何想法? –