コード例 #1
0
        public async Task <JsonWebToken> Handle(SignIn request, CancellationToken cancellationToken)
        {
            var email    = request.Email;
            var password = request.Password;

            var user = await _userRepository.GetAsync(email);

            if (user == null || !user.ValidatePassword(password, _passwordHasher))
            {
                throw new IdentityException(Codes.InvalidCredentials,
                                            "Invalid credentials.");
            }

            var refreshToken = new RefreshToken(user, _passwordHasher);
            var claims       = await _claimsProvider.GetAsync(user.Id);

            var jwt = _jwtService.CreateToken(user.Id.ToString("N"), user.Role, claims);

            jwt.RefreshToken = refreshToken.Token;
            await _refreshTokenRepository.AddAndSaveAsync(refreshToken);

            return(jwt);
        }