public static ClaimsIdentity ToClaimsIdentity(this ILoginInfo @this)
        {
            var claims = new List <Claim> {
                new Claim(ClaimTypes.Name, @this.DisplayName.OrEmpty()),
                new Claim(ClaimTypes.Expiration, DateTimeOffset.UtcNow.Add(@this.Timeout ?? DistantFuture).ToString()),
            };

            if (@this.ID.HasValue())
            {
                claims.Add(new Claim(ClaimTypes.NameIdentifier, @this.ID));
            }
            if (@this.Email.HasValue())
            {
                claims.Add(new Claim(ClaimTypes.Email, @this.Email));
            }

            var roles = @this.GetRoles().OrEmpty().ToString(",");

            if (roles.HasValue())
            {
                claims.Add(new Claim(ClaimTypes.Role, roles));
            }

            return(new ClaimsIdentity(claims, "Olive"));
        }
Exemplo n.º 2
0
 public GenericLoginInfo(ILoginInfo copyFrom)
 {
     Roles       = copyFrom.GetRoles().ToArray();
     DisplayName = copyFrom.DisplayName;
     ID          = copyFrom.ID;
     Email       = copyFrom.Email;
     Timeout     = copyFrom.Timeout;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Impersonates the specified user by the current admin user.
        /// </summary>
        public static async Task Impersonate(ILoginInfo user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            user = new GenericLoginInfo
            {
                DisplayName = user.DisplayName,
                Email       = user.Email,
                ID          = user.ID,
                Timeout     = user.Timeout,
                Roles       = user.GetRoles().Concat(IMPERSONATOR_ROLE).ToArray()
            };

            await user.LogOn();
        }
Exemplo n.º 4
0
        public static ClaimsIdentity ToClaimsIdentity(this ILoginInfo info)
        {
            var claims = new List <Claim> {
                new Claim(ClaimTypes.Name, info.DisplayName.OrEmpty())
            };

            if (info.ID.HasValue())
            {
                claims.Add(new Claim(ClaimTypes.NameIdentifier, info.ID));
            }
            if (info.Email.HasValue())
            {
                claims.Add(new Claim(ClaimTypes.Email, info.Email));
            }

            foreach (var role in info.GetRoles().OrEmpty())
            {
                claims.Add(new Claim(ClaimTypes.Role, role));
            }

            return(new ClaimsIdentity(claims, "Olive"));
        }
Exemplo n.º 5
0
        public static ClaimsIdentity ToClaimsIdentity(this ILoginInfo @this)
        {
            var claims = new List <Claim> {
                new Claim(ClaimTypes.Name, @this.DisplayName.OrEmpty())
            };

            if (@this.ID.HasValue())
            {
                claims.Add(new Claim(ClaimTypes.NameIdentifier, @this.ID));
            }
            if (@this.Email.HasValue())
            {
                claims.Add(new Claim(ClaimTypes.Email, @this.Email));
            }

            var roles = @this.GetRoles().OrEmpty().ToString(",");

            if (roles.HasValue())
            {
                claims.Add(new Claim(ClaimTypes.Role, roles));
            }

            return(new ClaimsIdentity(claims, "Olive"));
        }