public void GivenExistingUserDTO_WhenAuthenticate_ThenReturnOk()
        {
            //given
            UserDTO userDTO = new UserDTO {
                Email = "*****@*****.**", Password = "******"
            };

            _userAuthService.Authenticate(userDTO.Email, userDTO.Password).Returns(new JwtSecurityToken());

            //when
            OkObjectResult returnValue = (OkObjectResult)_usersController.Authenticate(userDTO).Result;

            //then
            Assert.Equal(200, returnValue.StatusCode);
        }
Exemplo n.º 2
0
        public IActionResult SignIn([FromBody] SignInRequestVM model)
        {
            JsonWebToken token = authenticationService.Authenticate(model.Login, model.Password, out UserVM user);

            return(Ok(new SignInResponseVM
            {
                Token = token,
                User = user
            }));
        }
Exemplo n.º 3
0
        public IActionResult Authenticate([FromBody] BusinessModelUser model)
        {
            var user = _userService.Authenticate(model.Username, model.Password);

            if (user == null)
            {
                return(BadRequest());
            }

            return(Ok(user));
        }
Exemplo n.º 4
0
        public IActionResult Authenticate(AuthenticateRequest model)
        {
            var response = _userAuthenticationService.Authenticate(model);

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

            return(Ok(response));
        }
Exemplo n.º 5
0
        public ActionResult <JwtSecurityToken> Authenticate([FromBody] UserDTO userDTO)
        {
            var securityToken = _userAuthService.Authenticate(userDTO.Email, userDTO.Password);

            if (securityToken != null)
            {
                var test = JsonConvert.SerializeObject(securityToken.RawData);
                return(Ok(test));
            }

            return(BadRequest("Email or Password incorrect!"));
        }
Exemplo n.º 6
0
 public ActionResult Login(LoginModel model, string returnUrl)
 {
     if (ModelState.IsValid)
     {
         authenticationService.Authenticate(model.UserName);
         return(Redirect(returnUrl ?? FormsAuthentication.DefaultUrl));
     }
     else
     {
         return(View("Login", model));
     }
 }
Exemplo n.º 7
0
        public async Task Call_Method_Authenticate_Returns_Token()
        {
            UserDTO user = new UserDTO()
            {
                UserName = "******",
                Password = "******"
            };

            var userWithToken = await userAuthenticationService.Authenticate(user);

            Assert.IsNotNull(userWithToken);
            Assert.IsNotNull(userWithToken.Token);
            Assert.IsNull(userWithToken.Password);
        }
        public IActionResult createUser([FromBody] User user)
        {
            if (_service.EmailExists(user.Email))
            {
                return(Conflict("User could not be added, email already in use."));
            }

            if (_service.UsernameExists(user.UserName))
            {
                return(Conflict("User could not be added, username already in use."));
            }

            var u = _service.AddUser(user);
            var t = _authService.Authenticate(user);

            return(Created($"/user/{u.Id}", new { Token = t }));
        }
Exemplo n.º 9
0
        public IActionResult Authenticate([FromBody] AuthenticateUserRequest request)
        {
            var token = _userAuthenticationService.Authenticate(request.Username, request.Password);

            if (string.IsNullOrWhiteSpace(token))
            {
                return(Unauthorized());
            }

            var user = _userService.GetByUsername(request.Username);

            return(Ok(new AuthenticateUserResponse
            {
                FirstName = user.FirstName,
                LastName = user.LastName,
                Token = token
            }));
        }
Exemplo n.º 10
0
    public IActionResult Login([FromBody] User user)
    {
        if (user == null)
        {
            return(BadRequest("Invalid client request"));
        }

        var dbUser = _service.VerifyCredentials(user);

        if (dbUser is not null)
        {
            var tokenString = _authService.Authenticate(dbUser);
            return(Ok(new { Token = tokenString }));
        }
        else
        {
            return(Unauthorized());
        }
    }
Exemplo n.º 11
0
 public ActionResult Login(string username, string password)
 {
     if (!_session.IsAuthenticated)
     {
         LoginAttemptResult loginAttemptResult = _userAuthenticationService.Authenticate(new Username(username),
                                                                                         new Password(password));
         if (!loginAttemptResult.Succeeded)
         {
             var errorMessages = new ErrorMessages {
                 GetLoginFailureMessage(loginAttemptResult)
             };
             TempData.ErrorMessages.Store(errorMessages);
             TempData.LoginReturnPage.Keep();
             return(RedirectToRoute(_siteMap.LoginPage));
         }
         _session.BeginAuthenticatedSession(loginAttemptResult.Account);
     }
     return(RedirectToRoute(TempData.LoginReturnPage.Get() ?? _siteMap.GetLandingPage(_session.AuthenticatedAccount)));
 }
Exemplo n.º 12
0
        protected override async Task <AuthenticateResult> HandleAuthenticateAsync()
        {
            if (!Request.Headers.ContainsKey("Authorization"))
            {
                return(AuthenticateResult.Fail("Missing Authorization Header"));
            }
            User user;

            try
            {
                var authHeader      = AuthenticationHeaderValue.Parse(Request.Headers["Authorization"]);
                var credentialBytes = Convert.FromBase64String(authHeader.Parameter);
                var credentials     = Encoding.UTF8.GetString(credentialBytes).Split(new[] { ':' }, 2);
                var username        = credentials[0];
                var password        = credentials[1];
                user = await authenticationService.Authenticate(username, password);
            }
            catch
            {
                return(AuthenticateResult.Fail("Invalid Authorization Header"));
            }

            if (user == null)
            {
                return(AuthenticateResult.Fail("Invalid Username or Password"));
            }

            var claims = new[] {
                new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
                new Claim(ClaimTypes.Name, user.Username),
            };
            var identity  = new ClaimsIdentity(claims, Scheme.Name);
            var principal = new ClaimsPrincipal(identity);
            var ticket    = new AuthenticationTicket(principal, Scheme.Name);

            return(AuthenticateResult.Success(ticket));
        }
Exemplo n.º 13
0
 public UserDetails Authenticate([FromQuery] string userName, [FromQuery] string password)
 {
     return(_authService.Authenticate(userName, password));
 }