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"));
        }
Exemple #2
0
 public GenericLoginInfo(ILoginInfo copyFrom)
 {
     Roles       = copyFrom.GetRoles().ToArray();
     DisplayName = copyFrom.DisplayName;
     ID          = copyFrom.ID;
     Email       = copyFrom.Email;
     Timeout     = copyFrom.Timeout;
 }
        /// <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();
        }
        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"));
        }
        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"));
        }