Cookie-based authentication

Once the Identity tables are created in the database, run the application once to seed a default user. (This is an optional step, for demo purpose we seed the database).

Create AuthController, copy the following piece of code to read the username and password, validate against the identity database, and return cookie:

 using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.AspNetCore.Mvc; using System.Threading.Tasks; namespace BudegetIdentityDemo.Controllers { public class AuthController : Controller { private readonly SignInManager<IdentityUser> _signInMgr; public AuthController(SignInManager<IdentityUser> signInMgr) { _signInMgr = signInMgr; } [HttpPost("api/auth/login")] ...

Get Mastering ASP.NET Web API now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.