public void CrossTokenValidateToken(CrossTokenTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.CrossTokenValidateToken", theoryData); try { var samlToken = IdentityUtilities.CreateEncodedSaml(theoryData.SecurityTokenDescriptor, theoryData.SamlTokenHandler); var saml2Token = IdentityUtilities.CreateEncodedSaml2(theoryData.SecurityTokenDescriptor, theoryData.Saml2TokenHandler); var jwtToken = IdentityUtilities.CreateEncodedJwt(theoryData.SecurityTokenDescriptor, theoryData.JwtTokenHandler); var samlPrincipal = theoryData.SamlTokenHandler.ValidateToken(samlToken, theoryData.TokenValidationParameters, out SecurityToken samlValidatedToken); var saml2Principal = theoryData.Saml2TokenHandler.ValidateToken(saml2Token, theoryData.TokenValidationParameters, out SecurityToken saml2ValidatedToken); var jwtPrincipal = theoryData.JwtTokenHandler.ValidateToken(jwtToken, theoryData.TokenValidationParameters, out SecurityToken jwtValidatedToken); // false = ignore type of objects, we expect all objects in the principal to be of same type (no derived types) context.IgnoreType = false; IdentityComparer.AreEqual(samlPrincipal, saml2Principal, context); // true = ignore properties of claims, any mapped claims short to long for JWT's will have a property that represents the short type. context.IgnoreProperties = true; IdentityComparer.AreEqual(samlPrincipal, jwtPrincipal, context); IdentityComparer.AreEqual(saml2Principal, jwtPrincipal, context); } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex); } TestUtilities.AssertFailIfErrors(context); }
static ClaimSets() { AllReserved = new List <Claim>() { new Claim(JwtRegisteredClaimNames.Actort, IdentityUtilities.CreateJwtSecurityToken(IdentityUtilities.ActorIssuer, IdentityUtilities.ActorIssuer).ToString()), new Claim(JwtRegisteredClaimNames.Aud, "audClaimSets.Value"), new Claim(JwtHeaderParameterNames.Typ, "BADDTYPE"), new Claim(JwtRegisteredClaimNames.Exp, "BADDATEFORMAT"), new Claim(JwtRegisteredClaimNames.Iat, "issuedatClaimSets.Value"), new Claim(JwtRegisteredClaimNames.Iss, "issuerClaimSets.Value"), new Claim(JwtRegisteredClaimNames.Jti, "jwtIdClaimSets.Value"), new Claim(JwtRegisteredClaimNames.Nbf, "BADDATEFORMAT"), new Claim(JwtRegisteredClaimNames.Exp, EpochTime.GetIntDate(DateTime.UtcNow + TimeSpan.FromHours(1)).ToString()), new Claim(JwtRegisteredClaimNames.Nbf, EpochTime.GetIntDate(DateTime.UtcNow).ToString()), new Claim(JwtRegisteredClaimNames.Prn, "princlipalClaimSets.Value"), new Claim(JwtRegisteredClaimNames.Sub, "Subject.Value"), new Claim(JwtRegisteredClaimNames.Typ, "Type.Value"), }; DefaultClaims = new List <Claim> { new Claim(ClaimTypes.Country, "USA", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim(ClaimTypes.Email, "*****@*****.**", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim(ClaimTypes.GivenName, "Bob", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim(ClaimTypes.HomePhone, "555.1212", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim(ClaimTypes.Role, "Developer", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim(ClaimTypes.Role, "Sales", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim(ClaimsIdentity.DefaultNameClaimType, "Jean-Sébastien", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("role", "role1", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("roles", "roles1", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), }; DerivedGlobalClaims = new List <Claim>() { new Claim("Arabic", @"?????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("Turkish1", @"??I?i???çöÇÖ", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("Turkish2", @"???Ö", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("Chinese1", @"???", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("Chinese2", @"??", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("Japanese1", @"???", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("Japanese2", @"????<", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("ExtA1", @"????????????????????????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("ExtA2", @"???????????????????????????????????????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("ExtA3", @"????????????????????????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("ExtA4", @"?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("ExtA4", @"????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("ExtB1", @"????????????????????????????????????????????????????????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("ExtB2", @"??????????????????????????????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("ExtB3", @"????????????????????????????????????????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("ExtB4", @"????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????<", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("ExtB5", @"??????????????????????????????????????????????????????????????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("EnteringIntlChars1", @"????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("EnteringIntlChars2", @"????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("EnteringIntlChars3", @"????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("EnteringIntlChars4", @"??a??z??4??M??f??N??g??S??l??T??m??Y??r??Y??E??K??7??P??i??P??i??U??n??)??B??G??3??L??e??M??9??R??k??S??l??X??q??X??D??]??v??1??J??c??K??7??P??i??Q??i", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("EnteringIntlChars5", @"??9??R??k??S??l??X??q??Y??E??J??gtOyYeqMY9E6??O??h??P??i??U??n??)??A??Z??s??y??e??L??8??Q??j??R??k??????????????????????W??p??X??D??]??v??1??I??b??J??6??O??h??P??i??U??n??)??B??Z??s", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("CommonSurrogates1", @"??????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("CommonSurrogates2", @"??????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("CommonSurrogates3", @"??????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("CommonSurrogates4", @"??????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("STBSample1", @"!#)6=@Aa}~<", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("STBSample2", @"????????????????????????????€????????????????????????????????????????€", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("STBSample3", @"??????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("STBSample4", @"????????????????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("STBSample5", @"??????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("STBSample6", @"???????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("STBSample7", @"??????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("STBSample8", @"???????????????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("STBSample9", @"??????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), new Claim("STBSample10", @"??????????", ClaimValueTypes.String, IdentityUtilities.DefaultIssuer), }; var claims = new List <Claim>(); claims.AddRange(DefaultClaims); foreach (var claim in DefaultClaims) { claims.Add(new DerivedClaim(claim, Guid.NewGuid().ToString(), Guid.NewGuid().ToByteArray())); } DerivedClaims = claims; claims = new List <Claim>(); foreach (var claim in DerivedGlobalClaims) { claims.Add(new DerivedClaim(claim, Guid.NewGuid().ToString(), Guid.NewGuid().ToByteArray())); } DerivedGlobalClaims = claims; claims = new List <Claim>(); claims.AddRange(DefaultClaims); claims.AddRange(DefaultClaims); DefaultDuplicatedClaims = claims; DefaultClaimsIdentity = new ClaimsIdentity(DefaultClaims, IdentityUtilities.DefaultAuthenticationType); DefaultClaimsIdentity.Label = IdentityUtilities.DefaultClaimsIdentityLabel; DefaultClaimsIdentityClaimsDuplicated = new ClaimsIdentity(DefaultDuplicatedClaims, IdentityUtilities.DefaultAuthenticationType); DefaultClaimsIdentityClaimsDuplicated.Label = IdentityUtilities.DefaultClaimsIdentityLabelDup; ClaimsIdentityDerivedClaims = new ClaimsIdentity(DerivedClaims, IdentityUtilities.DefaultAuthenticationType); DerivedClaimsIdentityDefaultClaims = new DerivedClaimsIdentity(DefaultClaims, Guid.NewGuid().ToString(), Guid.NewGuid().ToByteArray()); DerivedClaimsIdentityDerivedClaims = new DerivedClaimsIdentity(DerivedClaims, Guid.NewGuid().ToString(), Guid.NewGuid().ToByteArray()); DefaultClaimsPrincipal = new ClaimsPrincipal(DefaultClaimsIdentity); }