Beispiel #1
0
        public async Task Authenticate_WithCorrectUsernameAndPassword_ReturnStatusCodeOK()
        {
            // Arrange
            var request = new AuthenticationRequest
            {
                Username = "******",
                Password = "******"
            };

            var response = new AuthenticationResponse
            {
                Username = "******",
                Role     = "Admin",
                Token    = "AAAAA"
            };

            userService
            .AuthenticateAsync(Arg.Any <string>(), Arg.Any <string>())
            .Returns(Task.FromResult(response));

            // Act
            var actionResult = await usersController.Authenticate(request);

            var objectResult = actionResult as OkObjectResult;

            // Assert
            Assert.NotNull(objectResult);
            Assert.Equal((int)System.Net.HttpStatusCode.OK, objectResult.StatusCode);
        }
Beispiel #2
0
        public async Task <IActionResult> Authenticate([FromBody] LoginDto loginDto)
        {
            var token = await _usersService.AuthenticateAsync(loginDto);

            if (token == null)
            {
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }
            return(Ok(token));
        }
        public async Task <IActionResult> Authenticate([FromBody] AuthenticationRequest request)
        {
            var response = await userService.AuthenticateAsync(request.Username, request.Password);

            if (response == null)
            {
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }

            return(Ok(response));
        }
        public async Task <IActionResult> Authenticate([FromBody] AuthenticateModel model)
        {
            var user = await _userService.AuthenticateAsync(model.Username, model.Password);

            if (user == null)
            {
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }

            return(Ok(user));
        }
        public async Task <ActionResult <AuthenticatedUser> > Login([FromBody] UserLogin userLogin)
        {
            logger.LogDebug($"Attempting to authenticate user {userLogin.Username}");

            var authenticatedUser = await usersService.AuthenticateAsync(userLogin.Username, userLogin.Password);

            if (authenticatedUser == null)
            {
                logger.LogDebug($"Failed to authenticate user {userLogin.Username}");
                return(BadRequest("Username or password is incorrect"));
            }

            return(Ok(new AuthenticatedUser(authenticatedUser)));
        }
        public async Task <IActionResult> AuthenticateAsync([FromBody] LoginRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var domainRequest = mapper.Map <Domains.LoginRequest>(request);
            var resultToken   = await usersService.AuthenticateAsync(domainRequest);

            if (string.IsNullOrEmpty(resultToken))
            {
                return(BadRequest("Username or password is incorrect."));
            }

            return(Ok(resultToken));
        }
Beispiel #7
0
 public void AuthenticateAsync_ProvidingNull_ThrowsArgumentNull()
 {
     Assert.ThrowsAsync <ArgumentNullException>(() => service.AuthenticateAsync(null));
 }