public object Post([FromBody] UsuarioRequest request, [FromServices] SigningConfigurations signingConfigurations, [FromServices] TokenConfigurations tokenConfigurations) { UsuarioAutenticadoResponse response = _servicePessoa.AutenticarPessoa(request.Cpf, request.Senha); if (response.Cpf != null) { ClaimsIdentity identity = new ClaimsIdentity( new GenericIdentity(response.Id.ToString(), "Id"), new[] { new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString("N")), //new Claim(JwtRegisteredClaimNames.UniqueName, response.Usuario) new Claim("Usuario", JsonConvert.SerializeObject(response)) } ); //Criando a identidade e configuração do Token da API DateTime dataCriacao = DateTime.Now; DateTime dataExpiracao = dataCriacao + TimeSpan.FromSeconds(tokenConfigurations.Seconds); var handler = new JwtSecurityTokenHandler(); var securityToken = handler.CreateToken(new SecurityTokenDescriptor { Issuer = tokenConfigurations.Issuer, Audience = tokenConfigurations.Audience, SigningCredentials = signingConfigurations.SigningCredentials, Subject = identity, NotBefore = dataCriacao, Expires = dataExpiracao }); var token = handler.WriteToken(securityToken); return(new { authenticated = true, created = dataCriacao.ToString("yyyy-MM-dd HH:mm:ss"), expiration = dataExpiracao.ToString("yyyy-MM-dd HH:mm:ss"), accessToken = token, message = "Usuário logado", Nome = response.Nome, CPF = response.Cpf, id = response.Id }); } else { // return CreatedAtAction("Post", new { HttpStatusCode.BadRequest }); return(new { authenticated = false, message = "cpf ou senha inválidos." }); } }