Skip to content
Public template

About

No description, website, or topics provided.

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

DotNetStarterKit

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.

Why This Kit

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 + rotating refresh_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.

Prerequisites

  • .NET SDK 10
  • PostgreSQL 15+
  • Docker (optional, recommended for quick start)

Quick Start (Local)

  1. Configure src/DotNetStarterKit.Api/appsettings.Development.json or environment variables.
  2. Run:
dotnet build DotNetStarterKit.sln
dotnet test DotNetStarterKit.sln
dotnet run --project src/DotNetStarterKit.Api

Quick Start (Docker Compose)

  1. Copy env template:
cp .env.example .env

Windows PowerShell:

Copy-Item .env.example .env
  1. Edit .env at least:
  • POSTGRES_PASSWORD
  • JWT_KEY
  1. Start:
docker compose up --build -d
  1. Verify:
  • API health: http://localhost:8080/health
  • API readiness: http://localhost:8080/ready
  • PostgreSQL: localhost:5432
  1. Stop:
docker compose down

Health and Readiness

  • GET /health: process is up.
  • GET /ready: app can serve traffic and database is reachable.

Migration Strategy (Opinionated Default)

  • 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).

Testing and Coverage (Current State)

Run:

dotnet test DotNetStarterKit.sln

Current test scope:

  • tests/DotNetStarterKit.UnitTests/Logging/LogQueueMaskingTests.cs
  • tests/DotNetStarterKit.UnitTests/Auth/AuthServiceTests.cs
  • Auth tests use real Identity (UserManager, SignInManager) + EF Core InMemory provider and seed users/tokens.
  • External systems are faked only where needed (IMailService, IAppLocalizer, ICurrentUser).

Coverage collection:

dotnet test DotNetStarterKit.sln --collect:"XPlat Code Coverage"

Logging and Observability Scope

  • 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.

Configuration You Must Change

Required:

  • ConnectionStrings:Default
  • Jwt:Issuer
  • Jwt:Key (random 32+ chars)

Commonly needed:

  • Seed:*
  • Cors:AllowedOrigins
  • ForwardedHeaders:*
  • RateLimiting:*
  • Localization:*
  • Mailjet:*
  • R2:*

Use environment variables or secret manager for real environments.

Security Notes

  • 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.

Reverse Proxy / Cloudflare / Nginx

Examples:

  • deployment/nginx/nginx.conf.example
  • deployment/nginx/cloudflare-realip.conf.example

Rules:

  • Trust forwarded headers only from known proxies/networks.
  • Keep origin private behind proxy/CDN.

Optional Modules

  • Mail: IMailService with Mailjet provider and no-op fallback.
  • Object storage: IObjectStorage with Cloudflare R2 provider and disabled fallback.

Repository Layout

  • src/DotNetStarterKit.Api
  • src/DotNetStarterKit.Application
  • src/DotNetStarterKit.Domain
  • src/DotNetStarterKit.Infrastructure
  • tests/DotNetStarterKit.UnitTests
  • deployment/nginx/*

Release Checklist

  • 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 and License

  • Contributing guide: CONTRIBUTING.md
  • License: LICENSE (MIT)

About

No description, website, or topics provided.

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages