示例#1
0
        public static AuthenticationTicket Read([NotNull] BinaryReader reader)
        {
            if (reader.ReadInt32() != FormatVersion)
            {
                return(null);
            }

            string authenticationType = reader.ReadString();
            string nameClaimType      = ReadWithDefault(reader, DefaultValues.NameClaimType);
            string roleClaimType      = ReadWithDefault(reader, DefaultValues.RoleClaimType);
            int    count  = reader.ReadInt32();
            var    claims = new Claim[count];

            for (int index = 0; index != count; ++index)
            {
                string type           = ReadWithDefault(reader, nameClaimType);
                string value          = reader.ReadString();
                string valueType      = ReadWithDefault(reader, DefaultValues.StringValueType);
                string issuer         = ReadWithDefault(reader, DefaultValues.LocalAuthority);
                string originalIssuer = ReadWithDefault(reader, issuer);
                claims[index] = new Claim(type, value, valueType, issuer, originalIssuer);
            }
            var identity   = new ClaimsIdentity(claims, authenticationType, nameClaimType, roleClaimType);
            var properties = PropertiesSerializer.Read(reader);

            return(new AuthenticationTicket(identity, properties));
        }
示例#2
0
        public static void Write([NotNull] BinaryWriter writer, [NotNull] AuthenticationTicket model)
        {
            writer.Write(FormatVersion);
            ClaimsIdentity identity = model.Identity;

            writer.Write(identity.AuthenticationType);
            WriteWithDefault(writer, identity.NameClaimType, DefaultValues.NameClaimType);
            WriteWithDefault(writer, identity.RoleClaimType, DefaultValues.RoleClaimType);
            writer.Write(identity.Claims.Count());
            foreach (var claim in identity.Claims)
            {
                WriteWithDefault(writer, claim.Type, identity.NameClaimType);
                writer.Write(claim.Value);
                WriteWithDefault(writer, claim.ValueType, DefaultValues.StringValueType);
                WriteWithDefault(writer, claim.Issuer, DefaultValues.LocalAuthority);
                WriteWithDefault(writer, claim.OriginalIssuer, claim.Issuer);
            }
            PropertiesSerializer.Write(writer, model.Properties);
        }
示例#3
0
 static DataSerializers()
 {
     Properties = new PropertiesSerializer();
     Ticket     = new TicketSerializer();
 }