Exemple #1
0
        public static AuthenticationTicket Read(BinaryReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (reader.ReadInt32() != 3)
            {
                return(null);
            }
            string str  = reader.ReadString();
            string str1 = TicketSerializer.ReadWithDefault(reader, "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name");
            string str2 = TicketSerializer.ReadWithDefault(reader, "http://schemas.microsoft.com/ws/2008/06/identity/claims/role");
            int    num  = reader.ReadInt32();

            Claim[] claim = new Claim[num];
            for (int i = 0; i != num; i++)
            {
                string str3 = TicketSerializer.ReadWithDefault(reader, str1);
                string str4 = reader.ReadString();
                string str5 = TicketSerializer.ReadWithDefault(reader, "http://www.w3.org/2001/XMLSchema#string");
                string str6 = TicketSerializer.ReadWithDefault(reader, "LOCAL AUTHORITY");
                string str7 = TicketSerializer.ReadWithDefault(reader, str6);
                claim[i] = new Claim(str3, str4, str5, str6, str7);
            }
            ClaimsIdentity claimsIdentity = new ClaimsIdentity(claim, str, str1, str2);

            if (reader.ReadInt32() > 0)
            {
                claimsIdentity.BootstrapContext = new BootstrapContext(reader.ReadString());     //--> Contains: BootstrapContext(RSASecurityToken token, SecurityTokenHandler tokenHandler)
            }
            return(new AuthenticationTicket(claimsIdentity, PropertiesSerializer.Read(reader))); //--> Properties contain the Expires, Issued values
        }
        public AuthenticationProperties Deserialize(byte[] data)
        {
            AuthenticationProperties authenticationProperty;

            using (MemoryStream memoryStream = new MemoryStream(data))
            {
                using (BinaryReader binaryReader = new BinaryReader(memoryStream))
                {
                    authenticationProperty = PropertiesSerializer.Read(binaryReader);
                }
            }
            return(authenticationProperty);
        }
 public byte[] Serialize(AuthenticationProperties model)
 {
     byte[] array;
     using (MemoryStream memoryStream = new MemoryStream())
     {
         using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
         {
             PropertiesSerializer.Write(binaryWriter, model);
             binaryWriter.Flush();
             array = memoryStream.ToArray();
         }
     }
     return(array);
 }
Exemple #4
0
        public static void Write(BinaryWriter writer, AuthenticationTicket model)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            writer.Write(3);
            ClaimsIdentity identity = model.Identity;

            writer.Write(identity.AuthenticationType);
            TicketSerializer.WriteWithDefault(writer, identity.NameClaimType, "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name");
            TicketSerializer.WriteWithDefault(writer, identity.RoleClaimType, "http://schemas.microsoft.com/ws/2008/06/identity/claims/role");
            writer.Write(identity.Claims.Count <Claim>());
            foreach (Claim claim in identity.Claims)
            {
                TicketSerializer.WriteWithDefault(writer, claim.Type, identity.NameClaimType);
                writer.Write(claim.Value);
                TicketSerializer.WriteWithDefault(writer, claim.ValueType, "http://www.w3.org/2001/XMLSchema#string");
                TicketSerializer.WriteWithDefault(writer, claim.Issuer, "LOCAL AUTHORITY");
                TicketSerializer.WriteWithDefault(writer, claim.OriginalIssuer, claim.Issuer);
            }
            BootstrapContext bootstrapContext = identity.BootstrapContext as BootstrapContext;

            if (bootstrapContext == null || string.IsNullOrWhiteSpace(bootstrapContext.Token))
            {
                writer.Write(0);
            }
            else
            {
                writer.Write(bootstrapContext.Token.Length);
                writer.Write(bootstrapContext.Token);
            }
            PropertiesSerializer.Write(writer, model.Properties);
        }