public static new NumberToken Parse(TokenStringReader reader) { string num = ""; int c; if (reader.HasNext()) { c = reader.PeekForward(); if (!isDigit(c)) { throw new Exception("Number token not valid at " + reader.Position); } num += (char)c; reader.Forward(); } while (reader.HasNext()) { c = reader.PeekForward(); if (!isDigit(c)) { break; } num += (char)c; reader.Forward(); } return(new NumberToken(Convert.ToInt64(num, 2))); }
public static IdentifierToken Parse(TokenStringReader reader) { string id = ""; int c; if (reader.HasNext()) { c = reader.PeekForward(); if (!validFirstChar(c)) { throw new Exception("Name token not valid at " + reader.Position); } id += (char)c; reader.Forward(); } else { throw new Exception("Unexpected end of data."); } while (reader.HasNext()) { c = reader.PeekForward(); if (!validNameChar(c)) { break; } id += (char)c; reader.Forward(); } return(new IdentifierToken(id)); }
public void CanReadExpiredTokenFromDevTestIdp() { var expiredTokenFromDevTestIdp = @"<saml:Assertion MajorVersion=""1"" MinorVersion=""1"" AssertionID=""_e1736368-808e-4553-94a8-4b7166f55c7f"" Issuer=""http://devtest-idp.vfltest.dk/adfs/services/trust"" IssueInstant=""2016-02-15T12:46:05.383Z"" xmlns:saml=""urn:oasis:names:tc:SAML:1.0:assertion""><saml:Conditions NotBefore=""2016-02-15T12:46:05.368Z"" NotOnOrAfter=""2016-02-15T13:46:05.368Z""><saml:AudienceRestrictionCondition><saml:Audience>https://localhost.vfltest.dk/OBAPI/</saml:Audience></saml:AudienceRestrictionCondition></saml:Conditions><saml:AttributeStatement><saml:Subject><saml:NameIdentifier>[email protected]</saml:NameIdentifier><saml:SubjectConfirmation><saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</saml:ConfirmationMethod></saml:SubjectConfirmation></saml:Subject><saml:Attribute AttributeName=""role"" AttributeNamespace=""http://schemas.microsoft.com/ws/2008/06/identity/claims""><saml:AttributeValue>GBTC009Landmand</saml:AttributeValue><saml:AttributeValue>GOAlleSelvOprettere</saml:AttributeValue><saml:AttributeValue>GBTOLandmand</saml:AttributeValue><saml:AttributeValue>Domain Users</saml:AttributeValue><saml:AttributeValue>GTALCCSSystembrugere</saml:AttributeValue><saml:AttributeValue>GTALCDLIBasis</saml:AttributeValue><saml:AttributeValue>GTALCPlanteITBasis</saml:AttributeValue><saml:AttributeValue>GTAFocusFinderAdgang</saml:AttributeValue><saml:AttributeValue>GBTDLLandmand</saml:AttributeValue><saml:AttributeValue>GTALCLandmandDkMedlem</saml:AttributeValue><saml:AttributeValue>GTALCDCFFodertjek</saml:AttributeValue><saml:AttributeValue>GBTSOLandmand</saml:AttributeValue></saml:Attribute></saml:AttributeStatement><saml:AuthenticationStatement AuthenticationMethod=""urn:oasis:names:tc:SAML:1.0:am:password"" AuthenticationInstant=""2016-02-15T12:46:05.352Z""><saml:Subject><saml:NameIdentifier>[email protected]</saml:NameIdentifier><saml:SubjectConfirmation><saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</saml:ConfirmationMethod></saml:SubjectConfirmation></saml:Subject></saml:AuthenticationStatement><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=""#_e1736368-808e-4553-94a8-4b7166f55c7f""><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>Pc6RqG0JPFoNf6ARSinZuSiFUWLUvPhSfNopLNwQ1Zk=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>xCxcUt3MNSDwzIgIt6jZGKA/57e67hJjTphvTUA7dJ/NBXfpX7pwqjFAKtnhXHpcfpXGulhtTlqqK2pZwoQXIhLMLgX0C/jJbJ0zKVmn5l4/Zf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bmcgLSBkZXZ0ZXN0LWlkcC1sYW5kbWFuZGRrLnZmbHRlc3QuZGsgZGxicjKCEHmmxR6cLpCSTaP4cd3jDfgwCQYFKw4DAh0FAAOCAQEAelggKg6ShmJo1JHf+HAkwoWW40RYVAS3k12MU9MowO/OaotHhZ+bHduqMEhgEqqEIklVMo0mV58ofINRaNBGf/oLvQoJTohEvbhq6m/Da9d8kpQBdxG2SwsczsGqSml5FR7FlpYe3gxzdnpXa8cGj9R+OnauNdbU61w336WbiKDTUorh9n+wlOCUckV1ddcClVvwmcyq/zevrbN2euhvQN1+9RopP5hKl5wYPSLUP8OXZuA1X6lFG/QNjAT2wbjkR5UPDGXnollz977VXc1wSLaE1oDBkXF0Rfwafci9OSm4pYwqw61PE33IXq0t9SdGWOzgVFwCy1GOj8mpL7Kxcw==</X509Certificate></X509Data></KeyInfo></ds:Signature></saml:Assertion>"; var r = new TokenStringReader(); var principal = r.ReadUnvalidated(expiredTokenFromDevTestIdp); foreach (var claim in principal.Identities.First().Claims) { Console.WriteLine("{0} -> {1} -> {2}", claim.Issuer, claim.Type, claim.Value); } Assert.IsTrue(principal.Identity.IsAuthenticated); }
public static NumberToken Parse(TokenStringReader reader) { string num = ""; int c; bool isDec = false; if (reader.HasNext()) { c = reader.PeekForward(); if (!isDigit(c)) { throw new Exception("Number token not valid at " + reader.Position); } num += (char)c; reader.Forward(); } while (reader.HasNext()) { c = reader.PeekForward(); if (c != '.' && !isDigit(c)) { break; } if (c == '.') { if (isDec) { throw new Exception("Number token not valid at " + reader.Position); } isDec = true; } num += (char)c; reader.Forward(); } return(new NumberToken(double.Parse(num))); }