public async Task <IActionResult> Token(AuthModel model) { var isValid = await ApiProvider.AuthorizeAsync(model, CancellationToken.None); if (!isValid) { return(new UnauthorizedResult()); } var jwtSettings = new JwtSettings(DateTime.UtcNow); _configuration.GetSection("JwtSettings").Bind(jwtSettings); jwtSettings.Claims = GetClaims(model); var jwt = new JwtSecurityToken(jwtSettings.Issuer, jwtSettings.Audience, notBefore: jwtSettings.Now, claims: jwtSettings.Claims, expires: jwtSettings.Expires, signingCredentials: new SigningCredentials(jwtSettings.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256) ); var result = new TokenModel { Token = new JwtSecurityTokenHandler().WriteToken(jwt), Expires = jwtSettings.Expires, Login = model.Login, Type = model.AuthType }; return(new JsonResult(result)); }