OneLogin에서 Saml 응답의 유효성을 검사하려고하는데 간헐적 인 문제가 발생합니다. InResponseTo의 GUID 값이 숫자로 시작되면 예외 메시지와 함께 토큰 유효성 검사가 실패한 것 같습니다. ID4128 : 값이 유효한 SAML ID가 아닙니다. 매개 변수 이름 : 값. 그러나 GUID가 문자로 시작하면 토큰이 성공적으로 구문 분석됩니다.OneLogin에서 Saml 응답 확인
내 코드 :
public Saml2SecurityToken GetToken(string token)
{
var doc = new XmlDocument();
doc.LoadXml(token);
var assertionList = doc.GetElementsByTagName("Assertion", "urn:oasis:names:tc:SAML:2.0:assertion");
var handlers = FederatedAuthentication.FederationConfiguration.IdentityConfiguration.SecurityTokenHandlers;
var securityTokenXml = assertionList[0].OuterXml;
using (var stringReader = new StringReader(securityTokenXml))
{
using (var xmlreader = XmlReader.Create(stringReader))
{
return (Saml2SecurityToken) handlers.ReadToken(xmlreader);
}
}
}
내 토큰 :
<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="2.0" ID="pfx74145d78-55a9-dd78-00a0-2ee76d06a900" IssueInstant="2017-12-04T17:46:32Z">
<saml:Issuer>https://app.onelogin.com/saml/123</saml:Issuer>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
<ds:Reference URI="#pfx74145d78-55a9-dd78-00a0-2ee76d06a900">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
<ds:DigestValue>111</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>abc...</ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>abc...</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
<saml:Subject>
<saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">nameHere</saml:NameID>
<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
<saml:SubjectConfirmationData NotOnOrAfter="2017-12-04T17:49:32Z" Recipient="http://localhost/" InResponseTo="7ee0ebbd-3827-4e53-adc5-b8ec35917f2d" />
</saml:SubjectConfirmation>
</saml:Subject>
<saml:Conditions NotBefore="2017-12-04T17:43:32Z" NotOnOrAfter="2017-12-04T17:49:32Z">
<saml:AudienceRestriction>
<saml:Audience>AudienceName</saml:Audience>
</saml:AudienceRestriction>
</saml:Conditions>
<saml:AuthnStatement AuthnInstant="2017-12-04T17:46:31Z" SessionNotOnOrAfter="2017-12-05T17:46:32Z" SessionIndex="_fd124dd0-bb48-0135-5d75-0a8402be19a0">
<saml:AuthnContext>
<saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef>
</saml:AuthnContext>
</saml:AuthnStatement>
전체 스택 추적 :
at System.IdentityModel.Tokens.Saml2Id..ctor(String value)
at System.IdentityModel.Tokens.Saml2SecurityTokenHandler.ReadSubjectConfirmationData(XmlReader reader)
at System.IdentityModel.Tokens.Saml2SecurityTokenHandler.ReadSubjectConfirmationData(XmlReader reader)
at System.IdentityModel.Tokens.Saml2SecurityTokenHandler.ReadSubjectConfirmation(XmlReader reader)
at System.IdentityModel.Tokens.Saml2SecurityTokenHandler.ReadSubject(XmlReader reader)
at System.IdentityModel.Tokens.Saml2SecurityTokenHandler.ReadAssertion(XmlReader reader)
at System.IdentityModel.Tokens.Saml2SecurityTokenHandler.ReadToken(XmlReader reader)
at System.IdentityModel.Tokens.SecurityTokenHandlerCollection.ReadToken(XmlReader reader)
이 유효성을 검사/읽을 수있는 또 다른 방법이 있나요? 또는 InResponseTo를 무시하거나 제거 할 수 있습니까?
감사
예, 정확합니다. 내 AuthRequest에서 ID로 GUID를 보내고 있습니다. 내 ID가 어떻게 생성되는지를 변경하면 문제가 해결됩니다. – DaveMc