public IActionResult Authenticate(string username, string password)
        {
            var token = _authService.Authenticate(username, password);

            if (token == null)
            {
                return(Unauthorized());
            }

            return(Ok(token));
        }
Ejemplo n.º 2
0
        public IActionResult Authenticate([FromBody] AuthInfo user)
        {
            var token = _authService.Authenticate(user.Username, user.Password);

            if (token == null)
            {
                return(Unauthorized());
            }

            return(Ok(token));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <AuthenticationToken> > Token([FromBody] LoginModel model)
        {
            try
            {
                var token = await jwtAuthenticationService.Authenticate(model);

                return(token);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Login([FromBody] LoginRequestDto login)
        {
            if (string.IsNullOrEmpty(login.Username) || string.IsNullOrEmpty(login.Password))
            {
                return(BadRequest(new ErrorResponse(ErrorTypes.DataMissing.EnumDescription())));
            }

            var user = await jwtAuthenticationService.Authenticate(login.Username, login.Password);

            if (user is null)
            {
                return(Unauthorized(new ErrorResponse(ErrorTypes.IncorrectCredentials.EnumDescription())));
            }
            return(Ok(new { apiKey = user }));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult <List <string> > > AuthorizeWithLogin(Credentials Credentials, CancellationToken Cancel)
        {
            try
            {
                var Tokens = await JwtAuthenticationService.Authenticate(Credentials.Login, Credentials.Password, Cancel);

                if (Tokens.Item1 == null || Tokens.Item2 == null || Tokens.Item3 == null)
                {
                    return(Unauthorized());
                }

                return(Ok(new List <string> {
                    Tokens.Item1, Tokens.Item2, Tokens.Item3
                }));
            }
            catch
            {
                return(BadRequest());
            }
        }