我正在寻找在使用 WIF 时解决 SAML 令牌解析错误的方法。我对这项技术很陌生,所以我可能会遗漏一些明显的技术。
我编写了一个使用 WS-Federation 使用外部身份验证的示例 MVC 应用程序。我在本地使用 ThinkTecture 服务器进行了尝试,它就像一个魅力。但是,当我使用外部 STS 服务器(CA CloudMinder)尝试相同的方法时,我在 WIF 中遇到以下错误:
Application Error: 'Element' is an invalid XmlNodeType. System.Xml.XmlException XmlException System.Xml.XmlException: 'Element' is an invalid XmlNodeType.
at System.Xml.XmlReader.ReadEndElement()
at System.IdentityModel.Tokens.Saml2SecurityTokenHandler.ReadAssertion(XmlReader reader)
at System.IdentityModel.Tokens.Saml2SecurityTokenHandler.ReadToken(XmlReader reader)
at System.IdentityModel.Tokens.SecurityTokenHandlerCollection.ReadToken(XmlReader reader)
at System.IdentityModel.Services.TokenReceiver.ReadToken(String tokenXml, XmlDictionaryReaderQuotas readerQuotas, FederationConfiguration federationConfiguration)
at System.IdentityModel.Services.WSFederationAuthenticationModule.SignInWithResponseMessage(HttpRequestBase request)
at System.IdentityModel.Services.WSFederationAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs args)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) Void ReadEndElement() at System.Xml.XmlReader.ReadEndElement()
at System.IdentityModel.Tokens.Saml2SecurityTokenHandler.ReadAssertion(XmlReader reader)
at System.IdentityModel.Tokens.Saml2SecurityTokenHandler.ReadToken(XmlReader reader)
at System.IdentityModel.Tokens.SecurityTokenHandlerCollection.ReadToken(XmlReader reader)
at System.IdentityModel.Services.TokenReceiver.ReadToken(String tokenXml, XmlDictionaryReaderQuotas readerQuotas, FederationConfiguration federationConfiguration)
at System.IdentityModel.Services.WSFederationAuthenticationModule.SignInWithResponseMessage(HttpRequestBase request)
at System.IdentityModel.Services.WSFederationAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs args)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
这显然与发送回的实际 SAML 令牌的格式有关。我想我可以按如下方式捕获令牌本身并记录它:
void WSFederationAuthenticationModule_SignInError(object sender, ErrorEventArgs e)
{
var message = FederatedAuthentication.WSFederationAuthenticationModule.GetSignInResponseMessage(
new HttpRequestWrapper(HttpContext.Current.Request));
}
我不能分享实际的令牌本身。但我想知道,如果您知道如何解决这些错误的任何方法 - 例如手动验证令牌的某种方式。
任何建议表示赞赏。