public static AuthenticationTicket Read(BinaryReader reader) { if (reader.ReadInt32() != FormatVersion) { return(null); } string authenticationType = reader.ReadString(); string nameClaimType = reader.ReadString(); string roleClaimType = reader.ReadString(); int count = reader.ReadInt32(); var claims = new Claim[count]; for (int index = 0; index != count; ++index) { string type = reader.ReadString(); string value = reader.ReadString(); string valueType = reader.ReadString(); string issuer = reader.ReadString(); claims[index] = new Claim(type, value, valueType, issuer); } var identity = new ClaimsIdentity(claims, authenticationType, nameClaimType, roleClaimType); AuthenticationExtra extra = ExtraSerializer.Read(reader); return(new AuthenticationTicket(identity, extra)); }
public static void Write(BinaryWriter writer, AuthenticationTicket model) { writer.Write(FormatVersion); ClaimsIdentity identity = model.Identity; writer.Write(identity.AuthenticationType); writer.Write(identity.NameClaimType); writer.Write(identity.RoleClaimType); writer.Write(identity.Claims.Count()); foreach (var claim in identity.Claims) { writer.Write(claim.Type); writer.Write(claim.Value); writer.Write(claim.ValueType); writer.Write(claim.Issuer); } ExtraSerializer.Write(writer, model.Extra); }