示例#1
0
        public async Task <AuthResult> Authenticate(string userName, string password)
        {
            var user = await _userManager.FindByNameAsync(userName);

            if (user == null)
            {
                return(AuthResult.Failure(
                           new List <string>()
                {
                    "Invalid authentication request"
                }));
            }

            var isCorrect = await _userManager.CheckPasswordAsync(user, password);

            if (isCorrect)
            {
                var jwtToken = GenerateJwtToken(user);

                return(AuthResult.ResponseToken(jwtToken));
            }
            else
            {
                return(AuthResult.Failure(
                           new List <string>()
                {
                    "Invalid authentication request"
                }));
            }
        }