Exemplo n.º 1
0
        public IActionResult GetToken([FromBody] AuthenticationViewModel authentication)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid credentials."));
            }
            if (authentication.User != "joe" || authentication.Password != "blow")
            {
                return(NotFound("Invalid credentials."));
            }

            var user = new User()
            {
                Id = 1, Role = "Administrator"
            };

            return(Ok(new
            {
                token_type = "bearer",
                access_token = TokenServices.CreateToken(ClaimTypes.CreateClaims(user)),
                expiration_date = DateTime.UtcNow.AddMinutes(TokenServices._expirationInMinute),
            }));
        }