You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cookie base authentication/token base authentication
security context is stored in either cookie or token
user information is stored in database, credentials needs to be checked against stored data
After credentials verification, security is generated which is serialized into either cookie or web token
cookie/token is stored in both server and browser
security context is serialized back and forth b/w browser and server
ASP.NET Core Basics
Create cross-platform application (both Web API, and Web)
Middleware Pipeline: (authentication, authorization, etc). Each http request must pass through middleware one by one when it is coming or going back
Security Context
Security context stores all the information that user has for security purpose
All this infromation is stored in one single object called claims principles
claims principles also called Principle contain one or more identities of user
Principle present logged in user
Authorization Architecture
DbContext will look like this
usingIdentityProject.Models;usingMicrosoft.AspNetCore.Identity.EntityFrameworkCore;usingMicrosoft.EntityFrameworkCore;namespaceIdentityProject.Data{publicclassApplicationDbContext:IdentityDbContext<DefaultUser>{publicApplicationDbContext(DbContextOptionsoptions):base(options){}// This is where we will be adding the ModelsDbSet<Books>books{get;set;}}}
After that use scafolding to add identity to the project
usingMicrosoft.EntityFrameworkCore;usingMicrosoft.AspNetCore.Identity;usingIdentityProject.Data;varbuilder=WebApplication.CreateBuilder(args);// Add services to the container.builder.Services.AddControllersWithViews();builder.Services.AddDbContext<IdentityProject.Data.ApplicationDbContext>(
options =>options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));// Identity Db Context has been addedbuilder.Services.AddDefaultIdentity<IdentityProject.Models.DefaultUser>(options =>options.SignIn.RequireConfirmedAccount=true).AddEntityFrameworkStores<ApplicationDbContext>();varapp=builder.Build();// These are the middlewares// Configure the HTTP request pipeline.if(!app.Environment.IsDevelopment()){app.UseExceptionHandler("/Home/Error");// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.app.UseHsts();}app.UseHttpsRedirection();app.UseStaticFiles();app.UseRouting();app.UseAuthorization();app.UseAuthentication();app.MapControllerRoute(name:"default",pattern:"{controller=Home}/{action=Index}/{id?}");app.MapRazorPages();app.Run();