How chsakell/aspnet-core-identity works
Project type and purpose
• This is a full‑stack demonstration solution combining:
• An Angular Single‑Page Application (ClientApp)
• An ASP.NET Core MVC/Web API application (AspNetCoreIdentity) that hosts the SPA, serves Razor views, implements ASP.NET Core Identity functionality, and exposes business endpoints.
• A standalone IdentityServer (OpenID Connect/OAuth2 identity provider)
• A sample SocialNetwork.API microservice showing how protected APIs consume JWTs issued by IdentityServer.
• Purpose: Provide a comprehensive tutorial on ASP.NET Core Identity, EF Core integration, claims/role policies, external logins, two‑factor auth, and IdentityServer integration.
File structure
• Top‑level solution contains three projects:
• AspNetCoreIdentity (web host + Angular client)
• IdentityServer (identity provider UI + configuration, EF context, token endpoints)
• SocialNetwork.API (sample protected Web API)
• AspNetCoreIdentity/ClientApp: Angular modules, components, services for login, claims, admin, streaming, etc.
• AspNetCoreIdentity/Controllers & ViewModels: MVC controllers for account manage, home, weather, streaming, social accounts.
• Infrastructure folder: custom UserStore/Manager, EF DbInitializer, email sender, authorization handlers.
• IdentityServer: MVC UI for login/consent, EF ApplicationDbContext, Config.cs defining clients, resources, scopes.
• SocialNetwork.API: basic ASP.NET Core API with ContactsController protected by JWT Bearer.
• appsettings.json / launchSettings.json across projects define InMemory vs SQL Server stores, connection strings.
Key insights from README
• Multi‑stage tutorial covering: Identity fundamentals, EF store integration, authorization policies, IdentityServer, external auth, 2FA.
• Emphasizes use of OAuth2/OIDC flows via IdentityServer.
• Databases: AspNetCoreIdentityDb and IdentityServerDb (optionally in memory).
• Angular client uses oidc-client.js + an auth‑interceptor to attach tokens.
Main components
a. Angular SPA (ClientApp)
b. AspNetCoreIdentity Backend
– MVC/Razor pages (HomeController, ManageController, etc.)
– Web API endpoints (WeatherForecastController, StreamingController)
– ASP.NET Core Identity services (UserManager, SignInManager, custom stores)
– EF Core → AspNetCoreIdentityDb
c. IdentityServer
– UI (AccountController, ConsentController)
– Token endpoint, Discovery endpoint
– EF Core → IdentityServerDb
d. SocialNetwork.API
– Protected API endpoints (ContactsController)
– JWT Bearer authentication against IdentityServer
e. External systems (optional): Google/Facebook etc. for external auth
f. Client storage (browser localStorage / cookie)
Relationships and data flows
• User → Angular SPA (UI)
• SPA ⇄ AspNetCoreIdentity: initial HTML/CSS/JS, static assets, server‑side rendering (SSR) route.
• SPA → IdentityServer (via OIDC autorize & token endpoints) → receives id_token + access_token
• SPA → AspNetCoreIdentity Web API (with access_token in Authorization header)
• AspNetCoreIdentity → IdentityServer introspection (optional) or JWT validation middleware
• AspNetCoreIdentity → AspNetCoreIdentityDb (via EF) for user data, 2FA keys, external logins
• IdentityServer → IdentityServerDb (via EF) for clients, identity resources, persisted grants
• External login redirects: IdentityServer ↔ Third‑party providers
• SPA → SocialNetwork.API (with access_token)
• SocialNetwork.API → IdentityServer (JWT validation middleware)
Architectural patterns & principles
• SPA + Backend for UI & API (Separation of concerns)
• OAuth2/OIDC centralized auth via IdentityServer (Identity as a Service)
• Layered architecture: Presentation (Angular + Razor), Application (controllers/services), Infrastructure (EF stores, repositories), Data (SQL or InMemory).
• Extensible identity model via custom UserStore, claims, policies.
• Microservice‑style API (SocialNetwork.API) secured by bearer tokens.
Relevant technologies & frameworks
• Frontend: Angular, TypeScript, oidc-client.js
• Backend: ASP.NET Core MVC + Razor, ASP.NET Core Web API, ASP.NET Core Identity, IdentityServer4
• Data: Entity Framework Core, SQL Server (or InMemory provider)
• DevOps: dotnet CLI, npm, libman, appveyor CI config