コード例 #1
0
        public IActionResult Login(UserCredentials credentials)
        {
            var verifiedCredentials = _userRepository.VerifyCredentials(credentials);

            if (verifiedCredentials == null)
            {
                return(BadRequest("Username or password is incorrect!"));
            }

            var accessToken  = _jwtHelper.GetAccessToken(verifiedCredentials);
            var refreshToken = _jwtHelper.GetRefreshToken();

            if (!_refreshTokenRepository.AddRefreshToken(refreshToken, verifiedCredentials.Id))
            {
                return(Unauthorized());
            }

            return(Ok(new Token(accessToken, refreshToken)));
        }