Example #1
0
        private async Task <LoginResponseModel> CreateLoginResponseModelAsync(User user)
        {
            var isAdmin = await _userManager.IsInRoleAsync(user, "Admin");

            var token        = _tokenHandler.CreateToken(user, isAdmin);
            var refreshToken = _tokenHandler.CreateRefreshToken(user);

            var responseModel = new LoginResponseModel()
            {
                User = await ConvertToUserModelAsync(user),


                Token        = token,
                RefreshToken = refreshToken
            };

            return(responseModel);
        }
        public void CreateRefreshToken_TryCreateNewRefreshJwtTokenWithNullUser_ReturnNULL()
        {
            // Arrange
            JwtTokenHandler tokenHandler = new JwtTokenHandler(Config);
            var             user         = DummyUsers.TestUser();

            // Act
            string token = tokenHandler.CreateRefreshToken(null);

            // Assert
            Assert.IsNull(token);
        }
        public void ValidateRefreshToken_CheckIfJwtRefreshTokenIsValid_ReturnTrue()
        {
            // Arrange
            JwtTokenHandler tokenHandler = new JwtTokenHandler(Config);
            var             user         = DummyUsers.TestUser();
            string          token        = tokenHandler.CreateRefreshToken(user);

            // Act
            var result = tokenHandler.ValidateRefreshToken(token)
                         .Identity
                         .IsAuthenticated;

            // Assert
            Assert.IsTrue(result);
        }