Example #1
0
        private async Task <ClaimsIdentity> GetClaimsIdentityAsync(UserDto user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (user.UserName == null)
            {
                throw new ArgumentNullException(nameof(user.UserName));
            }

            if (user.Password == null)
            {
                throw new ArgumentNullException(nameof(user.Password));
            }

            var userToVerify = await _manager.FindByNameAsync(user.UserName);

            if (userToVerify == null)
            {
                throw new CredentialsException();
            }

            if (await _manager.CheckPasswordAsync(userToVerify, user.Password))
            {
                return(await _factory.GenerateClaimsIdentityAsync(userToVerify));
            }

            throw new CredentialsException();
        }