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 CreateToken_TryCreateNewJwtTokenWithNullUser_ReturnNULL() { // Arrange JwtTokenHandler tokenHandler = new JwtTokenHandler(Config); var user = DummyUsers.TestUser(); // Act string token = tokenHandler.CreateToken(null); // Assert Assert.IsNull(token); }
public void CreateToken_createNewToken_ReturnStringToken() { // Arrange JwtTokenHandler tokenHandler = new JwtTokenHandler(Config); var user = DummyUsers.TestUser(); // Act string token = tokenHandler.CreateToken(user, false); // Assert Assert.IsNotNull(token); }
public void ValidateToken_CheckIfJwtTokenIsValid_ReturnTrue() { // Arrange JwtTokenHandler tokenHandler = new JwtTokenHandler(Config); var user = DummyUsers.TestUser(); string token = tokenHandler.CreateToken(user); // Act var result = tokenHandler.ValidateToken(token) .Identity .IsAuthenticated; // Assert Assert.IsTrue(result); }