Exemple #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)));
        }
Exemple #2
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)));
        }