Пример #1
0
        private Task <bool> AddClaimsAsync(UserWithClaims user, ExternalLoginInfo externalLogin, string email, bool isFirst = false)
        {
            var newClaims = new List <Claim>();

            void AddClaim(Claim claim)
            {
                newClaims.Add(claim);

                user.Claims.Add(claim);
            }

            foreach (var squidexClaim in externalLogin.Principal.GetSquidexClaims())
            {
                AddClaim(squidexClaim);
            }

            if (!user.HasPictureUrl())
            {
                AddClaim(new Claim(SquidexClaimTypes.PictureUrl, GravatarHelper.CreatePictureUrl(email)));
            }

            if (!user.HasDisplayName())
            {
                AddClaim(new Claim(SquidexClaimTypes.DisplayName, email));
            }

            if (isFirst)
            {
                AddClaim(new Claim(SquidexClaimTypes.Permissions, Permissions.Admin));
            }

            return(MakeIdentityOperation(() => userManager.SyncClaimsAsync(user.Identity, newClaims)));
        }
Пример #2
0
        private static UserValues CreateUserValues(ExternalLoginInfo externalLogin, string email, IUser?user = null)
        {
            var values = new UserValues
            {
                CustomClaims = externalLogin.Principal.Claims.GetSquidexClaims().ToList()
            };

            if (user != null && !user.Claims.HasPictureUrl())
            {
                values.PictureUrl = GravatarHelper.CreatePictureUrl(email);
            }

            if (user != null && !user.Claims.HasDisplayName())
            {
                values.DisplayName = email;
            }

            return(values);
        }
Пример #3
0
        private IUser CreateUser(ExternalLoginInfo externalLogin, string email)
        {
            var user = userFactory.Create(email);

            foreach (var squidexClaim in externalLogin.Principal.GetSquidexClaims())
            {
                user.AddClaim(squidexClaim);
            }

            if (!user.HasPictureUrl())
            {
                user.SetPictureUrl(GravatarHelper.CreatePictureUrl(email));
            }

            if (!user.HasDisplayName())
            {
                user.SetDisplayName(email);
            }

            return(user);
        }
Пример #4
0
        private IUser CreateUser(ExternalLoginInfo externalLogin, string email)
        {
            var user = userFactory.Create(email);

            if (!externalLogin.Principal.HasClaim(x => x.Type == SquidexClaimTypes.SquidexPictureUrl))
            {
                user.SetClaim(SquidexClaimTypes.SquidexPictureUrl, GravatarHelper.CreatePictureUrl(email));
            }

            if (!externalLogin.Principal.HasClaim(x => x.Type == SquidexClaimTypes.SquidexDisplayName))
            {
                user.SetClaim(SquidexClaimTypes.SquidexDisplayName, email);
            }

            foreach (var squidexClaim in externalLogin.Principal.Claims.Where(c => c.Type.StartsWith(SquidexClaimTypes.Prefix)))
            {
                user.AddClaim(squidexClaim);
            }

            return(user);
        }
Пример #5
0
        private async Task <bool> AddClaimsAsync(UserWithClaims user, ExternalLoginInfo externalLogin, string email, bool isFirst = false)
        {
            var update = new UserValues
            {
                CustomClaims = externalLogin.Principal.GetSquidexClaims().ToList()
            };

            if (!user.HasPictureUrl())
            {
                update.PictureUrl = GravatarHelper.CreatePictureUrl(email);
            }

            if (!user.HasDisplayName())
            {
                update.DisplayName = email;
            }

            if (isFirst)
            {
                update.Permissions = new PermissionSet(Permissions.Admin);
            }

            return(await MakeIdentityOperation(() => userManager.SyncClaims(user.Identity, update)));
        }
Пример #6
0
 public static void SetPictureUrlFromGravatar(this IUser user, string email)
 {
     user.SetClaim(SquidexClaimTypes.SquidexPictureUrl, GravatarHelper.CreatePictureUrl(email));
 }