Tired of rebuilding auth, CSRF, refresh rotation, and safe logging in every new API? This starter kit gives you those pieces together, already wired for cookie-based JWT flows. It is optimized for solo/small teams: secure defaults first, minimal operational overhead second.
Problem:
- New projects repeatedly spend days on auth hardening, token lifecycle, request protection, and logging safety.
Solution:
- Opinionated ASP.NET Core API baseline with:
- Cookie-based JWT (
access_token+ rotatingrefresh_token) - CSRF protection for cookie auth
- Refresh-token hashing, rotation, reuse detection, session revocation
- Register/verify-email, login/refresh/logout/logout-all, forgot/reset-password flows
- Rate limiting policies for global and auth endpoints
- Request/response/error logging with masking and async queue persistence
- PostgreSQL + EF Core + Identity
- Localization (
en-US,tr-TR) - Forwarded headers support for reverse proxy/CDN deployments
Differentiator:
- Cookie JWT + CSRF + refresh rotation in one coherent default flow.
- Security-sensitive logging defaults (masking before persistence).
- Production-like startup behavior (auto migrations + optional seed) without requiring extra scripts.
- .NET SDK 10
- PostgreSQL 15+
- Docker (optional, recommended for quick start)
- Configure
src/DotNetStarterKit.Api/appsettings.Development.jsonor environment variables. - Run:
dotnet build DotNetStarterKit.sln
dotnet test DotNetStarterKit.sln
dotnet run --project src/DotNetStarterKit.Api- Copy env template:
cp .env.example .envWindows PowerShell:
Copy-Item .env.example .env- Edit
.envat least:
POSTGRES_PASSWORDJWT_KEY
- Start:
docker compose up --build -d- Verify:
- API health:
http://localhost:8080/health - API readiness:
http://localhost:8080/ready - PostgreSQL:
localhost:5432
- Stop:
docker compose downGET /health: process is up.GET /ready: app can serve traffic and database is reachable.
- On startup, app runs
ApplyMigrationsAndSeedAsync(). - Behavior is idempotent: existing schema/data is not recreated.
- This is the default strategy in this kit (not left as a TODO decision).
Run:
dotnet test DotNetStarterKit.slnCurrent test scope:
tests/DotNetStarterKit.UnitTests/Logging/LogQueueMaskingTests.cstests/DotNetStarterKit.UnitTests/Auth/AuthServiceTests.cs- Auth tests use real Identity (
UserManager,SignInManager) + EF CoreInMemoryprovider and seed users/tokens. - External systems are faked only where needed (
IMailService,IAppLocalizer,ICurrentUser).
Coverage collection:
dotnet test DotNetStarterKit.sln --collect:"XPlat Code Coverage"- This kit provides structured data fields in DB log records plus async queue-based persistence.
- Serilog/OpenTelemetry are intentionally not default to keep operational footprint low for solo/small deployments.
- If needed, those can be added on top as an adapter layer without rewriting auth/security flows.
Required:
ConnectionStrings:DefaultJwt:IssuerJwt:Key(random 32+ chars)
Commonly needed:
Seed:*Cors:AllowedOriginsForwardedHeaders:*RateLimiting:*Localization:*Mailjet:*R2:*
Use environment variables or secret manager for real environments.
- Password policy is intentionally relaxed (minimum 6) for starter usability.
- Tighten password policy in production.
- CSRF protection is enabled for state-changing requests with auth cookies.
- Refresh tokens are stored hashed.
- Sensitive fields are masked before log persistence.
- Forwarded headers trust is configurable through known proxies/networks.
Examples:
deployment/nginx/nginx.conf.exampledeployment/nginx/cloudflare-realip.conf.example
Rules:
- Trust forwarded headers only from known proxies/networks.
- Keep origin private behind proxy/CDN.
- Mail:
IMailServicewith Mailjet provider and no-op fallback. - Object storage:
IObjectStoragewith Cloudflare R2 provider and disabled fallback.
src/DotNetStarterKit.Apisrc/DotNetStarterKit.Applicationsrc/DotNetStarterKit.Domainsrc/DotNetStarterKit.Infrastructuretests/DotNetStarterKit.UnitTestsdeployment/nginx/*
- No real secrets in
appsettings*.json - Production secrets via environment variables or secret manager
- Strong
Jwt:Key - Real CORS origins configured
- Trusted proxy/network list verified
- Password policy tightened for production
- Smoke tests for login/refresh/csrf/forgot-reset flows
- Contributing guide:
CONTRIBUTING.md - License:
LICENSE(MIT)