示例#1
0
        public void Is_Unique()
        {
            // Act
            var id1 = new AuthId();
            var id2 = new AuthId();
            var id3 = new AuthId();
            var id4 = new AuthId();

            // Assert
            Assert.NotEqual(id1.ToString(), id2.ToString());
            Assert.NotEqual(id1.GetHashCode(), id2.GetHashCode());
            Assert.NotEqual(id1.ToBytes(), id2.ToBytes());

            Assert.NotEqual(id1.ToString(), id3.ToString());
            Assert.NotEqual(id1.GetHashCode(), id3.GetHashCode());
            Assert.NotEqual(id1.ToBytes(), id3.ToBytes());

            Assert.NotEqual(id1.ToString(), id4.ToString());
            Assert.NotEqual(id1.GetHashCode(), id4.GetHashCode());
            Assert.NotEqual(id1.ToBytes(), id4.ToBytes());


            Assert.NotEqual(id2.ToString(), id3.ToString());
            Assert.NotEqual(id2.GetHashCode(), id3.GetHashCode());
            Assert.NotEqual(id2.ToBytes(), id3.ToBytes());

            Assert.NotEqual(id2.ToString(), id4.ToString());
            Assert.NotEqual(id2.GetHashCode(), id4.GetHashCode());
            Assert.NotEqual(id2.ToBytes(), id4.ToBytes());


            Assert.NotEqual(id3.ToString(), id4.ToString());
            Assert.NotEqual(id3.GetHashCode(), id4.GetHashCode());
            Assert.NotEqual(id3.ToBytes(), id4.ToBytes());
        }
示例#2
0
        public void Is_Bootable(string startValue)
        {
            // Act
            var id = new AuthId(startValue);

            // Assert
            Assert.Equal(id.ToString(), startValue);
        }
示例#3
0
        internal void AddAuthentication(QueryStringParameters nvc)
        {
            if (IdType == AuthIdType.MainId)
            {
                nvc["auth-id"] = AuthId.ToString();
            }
            if (IdType == AuthIdType.SubId)
            {
                nvc["sub-auth-id"] = AuthId.ToString();
            }

            nvc["auth-password"] = AuthPassword;
        }
示例#4
0
        public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager, string authenticationType)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

            // Add custom user claims here
            TechDispatchContext db = new TechDispatchContext();

            userIdentity.AddClaim(new Claim("UserRole", db.TechDispatchRoles.FirstAsync(x => x.TechDispatchRoleId == TechDispatchRoleId).Result.Name));

            //to-do: Custom authorization. For now though, we simply add the authorization codes based on role.
            MyClaims = db.TechDispatchRoles.FirstAsync(x => x.TechDispatchRoleId >= TechDispatchRoleId).Result.AccessClaims;

            MyClaims.ForEach(d =>
                             userIdentity.AddClaim(new Claim(d.ClaimName, d.ClaimValue))
                             );

            userIdentity.AddClaim(new Claim("Name", Name == null ? Email : Name));
            userIdentity.AddClaim(new Claim("Email", Email));
            userIdentity.AddClaim(new Claim("AuthId", AuthId.ToString()));

            return(userIdentity);
        }