コード例 #1
0
        public async Task <TokensInfo> LoginAsync(string username, string password)
        {
            User user = await userRepository.FindByUsernameAsync(username);

            if (user == null)
            {
                throw new Exception("User does not exist!");
            }

            bool passwordCorrect = await userRepository.CheckPasswordAsync(user, password);

            if (!passwordCorrect)
            {
                throw new Exception("Password is incorrect!");
            }

            Claim[] userClaims = await GetAuthTokenClaimsForUserAsync(user);

            var accessToken  = tokenGenerator.GenerateTokenForClaims(userClaims);
            var refreshToken = refreshTokenFactory.GenerateRefreshToken();

            return(new TokensInfo(accessToken, refreshToken));
        }