Ejemplo n.º 1
0
        public async Task <UpdateResult> SetPasswordHashForUser(MongoExternalUser user, string hash)
        {
            var update = Builders <MongoExternalUser> .Update
                         .Set(s => s.Hash, hash);

            return(await collection.UpdateOneAsync(x => x.Username == user.Username, update));
        }
Ejemplo n.º 2
0
        public async Task <MongoExternalUser> AutoProvisionUser(string provider, string userId, List <Claim> claims)
        {
            var filter = Filters.Where(x => x.UsernameNormalized == userId.ToLowerInvariant().Normalize());
            var numberOfUsersWithUsername = await collection.CountAsync(filter);

            if (numberOfUsersWithUsername > 0)
            {
                throw new UserExistsException();
            }


            var nameClaim  = ClaimsFinder.ResolveNameClaim(userId, claims);
            var emailClaim = claims.ResolveEmailClaim();

            var user = new MongoExternalUser
            {
                ProviderId  = userId,
                Username    = nameClaim?.Value,
                Email       = emailClaim.Value,
                ProviderKey = provider,
                Claims      = claims.Select(x => new MongoClaim(x)).ToList()
            };

            user.SetMongoInternals();
            await collection.InsertOneAsync(user);

            return(user);
        }