我们正在使用IdentityServer3,到目前为止对此感到非常满意。
在MS和Thinktecture OWIN中间件的帮助下,我们已经非常轻松地保护MVC和ASP.NET Web API应用程序。
我们正在工作的客户端仍然有很多SOAP WCF服务,这就是我们遇到的问题。
我不会说谎,我对WCF经验还很远,我只在非常基本的情况下使用过它-了解basicHttpBinding,没有传输或消息安全性。
这是我要实现的目标:
我无法执行第三步。
ws2007FederationHttpBinding
带有TransportWithMessageCredential
安全模式。消息中包含BearerKey
,令牌的类型为urn:ietf:params:oauth:token-type:jwt
JwtSecurityTokenHandler
了System.IdentityModel.Tokens.Jwt
NuGet包中的BinarySecurityToken
XML元素中,而XML元素本身包装在GenericXmlSecurityElement
CreateChannelWithIssuedToken
的ChannelFactory
该令牌位于SOAP标头中,并传递给JwtSecurityTokenHandler
。
但是然后抛出一个异常:
System.ServiceModel.Security.MessageSecurityException: Message security verification failed. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Xml.XmlBufferReader.GetChars(Int32 offset, Int32 length, Char[] chars)
at System.Xml.XmlBufferReader.GetString(Int32 offset, Int32 length)
at System.Xml.StringHandle.GetString()
at System.Xml.XmlBaseReader.ReadEndElement()
at System.ServiceModel.Security.ReceiveSecurityHeader.ExecuteFullPass(XmlDictionaryReader reader)
at System.ServiceModel.Security.ReceiveSecurityHeader.Process(TimeSpan timeout, ChannelBinding channelBinding, ExtendedProtectionPolicy extendedProtectionPolicy)
at System.ServiceModel.Security.TransportSecurityProtocol.VerifyIncomingMessageCore(Message& message, TimeSpan timeout)
at System.ServiceModel.Security.TransportSecurityProtocol.VerifyIncomingMessage(Message& message, TimeSpan timeout)
--- End of inner exception stack trace ---
在JustDecompiling之后,进一步读取SOAP标头中的XML元素时似乎出现了错误。奇怪的是令牌是最后一个元素。整个消息如下所示:
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<a:Action s:mustUnderstand="1">http://tempuri.org/IService/GetListOfStrings</a:Action>
<a:MessageID>urn:uuid:5c22d4e2-f9b8-451a-b4ca-a844f41f7231</a:MessageID>
<ActivityId CorrelationId="554fc496-7c47-4063-9539-d25606f186b0" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">1213dcd7-55b7-4153-8a6d-92e0922f76dd</ActivityId>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo90CpMlUwLBOmEPkZ5C8fRQAAAAAVWkkf2rJS0qImBv+Yx1recUXdbBLjThDkAMkwfW3/2AACQAA</VsDebuggerCausalityData>
<a:To s:mustUnderstand="1">https://localhost.fiddler:44322/Service.svc</a:To>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<u:Timestamp u:Id="_0">
<u:Created>2015-05-21T06:41:45.362Z</u:Created>
<u:Expires>2015-05-21T06:46:45.362Z</u:Expires>
</u:Timestamp>
<wsse:BinarySecurityToken ValueType="urn:ietf:params:oauth:token-type:jwt" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><!-- Removed --></wsse:BinarySecurityToken>
</o:Security>
</s:Header>
<s:Body>
<GetListOfStrings xmlns="http://tempuri.org/" />
</s:Body>
</s:Envelope>
看起来好像有什么畸形的东西。从堆栈跟踪中,</o:Security>
由于正确地读取和处理了令牌,因此在读取end元素时必须引发异常。
我分叉了样本存储库,以便您随意查看。以下是相关的项目:
SelfHost (Minimal)
在sources
文件夹中。这是STSClients
解决方案中,WCF服务位于APIs
文件夹中Clients
解决方案中,WCF客户端是Console Client Credentials With Wcf
项目最好的启动方法是先启动STS,然后Right click -> Debug -> Start new instance
在WCF服务上启动,然后在WCF客户端上启动。
提前致谢!
我没有解决这个问题,但是IdentityServer的开发人员之一Dominick Baier找到了解决方法。
他认为异常来自WCF中的错误或WCF与Windows的不兼容JwtSecurityTokenHandler
。由于他认为WCF已完成,因此他不希望有人对此进行检查。
他的解决方案是将JWT令牌包装在SAML令牌中。然后,通过子类化SamlSecurityTokenHandler
,将其取回并针对的实例进行验证JwtSecurityTokenHandler
。
这里是链接:
每个人都玩得开心,现在:-)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句