BizBox.WebApi.Template 1.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet new install BizBox.WebApi.Template::1.2.0
                    
This package contains a .NET Template Package you can call from the shell/command line.

πŸš€ BizBox WebAPI Template

Version 1.2.0 - Enterprise-grade .NET 8 Web API template with HIPAA-ready security features

.NET Version PostgreSQL SignalR Security HIPAA License NuGet

πŸ“‹ Table of Contents


🎯 Overview

BizBox is a production-ready .NET 8 Web API template built with Clean Architecture principles, featuring enterprise-grade security, HIPAA-compliant audit logging, and comprehensive authentication/authorization systems. Perfect for healthcare, finance, and high-security applications.

🌟 Key Highlights

  • πŸ” Enterprise Security - Multi-layer defense with JWT, encrypted payloads, token blacklist
  • πŸ₯ HIPAA-Ready Features - Comprehensive audit logging, encryption at transit, secure logout
  • πŸ›‘οΈ Advanced Protection - BOLA/IDOR prevention with ticket-based authorization
  • πŸ’¬ Real-time Messaging - SignalR-powered WebSocket communication
  • πŸ—οΈ Clean Architecture - Maintainable, testable, scalable codebase
  • πŸ“Š Audit Trail - Automatic change tracking with old/new values, duration monitoring
  • πŸ”„ Session Management - Configurable single/multi-device policies with proper logout
  • πŸ“§ Invitation System - Email-based user onboarding
  • πŸš€ Template Ready - Install from NuGet, customize, and deploy

πŸ“ˆ Current Status

Metric Status Notes
Overall Security 82% Complete βœ… 16/19 items implemented
HIPAA Compliance 50% Complete 🚧 Core features done, encryption pending
Production Ready βœ… Yes Secure for non-PHI workloads
HIPAA PHI Ready 🚧 In Progress Encryption at rest pending

πŸ“¦ Installation (from NuGet)

Install the Template

dotnet new install BizBox.WebApi.Template

Create a New Project

# Create from template
dotnet new bizboxapi -n MyCompanyName.ProjectName

# Navigate to project
cd MyCompanyName.ProjectName

# Open in IDE
code .  # VS Code
# or
start MyCompanyName.ProjectName.sln  # Visual Studio

Verify Installation

dotnet new bizboxapi --help

πŸš€ Quick Start

1. Generate Secrets

# Windows
Generate-Secrets.bat

# Or PowerShell
.\Generate-Secrets.ps1

This will generate all required secrets and optionally save them to a .env file.

1. Database Setup

# Create PostgreSQL databases
createdb BizBox.Db           # Main database
createdb BizBox.AuditDb      # Audit database (HIPAA requirement)

2. Configure Secrets

cd MyProject.API

# Initialize User Secrets
dotnet user-secrets init

# Set required secrets
dotnet user-secrets set "ConnectionStrings:Default" "Host=localhost;Port=5432;Username=postgres;Password=yourpassword;Database=BizBox.Db"
dotnet user-secrets set "ConnectionStrings:AuditDb" "Host=localhost;Port=5432;Username=postgres;Password=yourpassword;Database=BizBox.AuditDb"
dotnet user-secrets set "Jwt:Key" "your-super-secret-jwt-key-min-32-characters-long"
dotnet user-secrets set "Encryption:Key" "12345678901234567890123456789012"
dotnet user-secrets set "Encryption:IV" "1234567890123456"
dotnet user-secrets set "SuperAdmin:Email" "admin@yourdomain.com"
dotnet user-secrets set "SuperAdmin:Password" "SecurePassword123!"

2. Apply Migrations

# Main database
dotnet ef database update --context ApplicationDbContext

# Audit database
dotnet ef database update --context AuditDbContext

3. Run the Application

dotnet run --project BizBox.API

API: https://localhost:7264
Swagger: https://localhost:7264/swagger
SignalR Test: https://localhost:7264/signalr-test-client.html

πŸ“– Need help? See docu/QUICK_START.md for detailed setup


✨ Features

πŸ” Security Features (82% Complete)

βœ… Implemented (16/19)

Authentication & Authorization:

  • βœ… JWT Authentication with HS256/RS256 support
  • βœ… Role-based authorization (Admin, SuperAdmin, Finance)
  • βœ… Token versioning (concurrent session detection)
  • βœ… Encrypted JWT payloads (AES-256)
  • βœ… Ticket-based authorization (BOLA/IDOR protection)
  • βœ… Password hashing (PBKDF2 with salt)
  • βœ… Email confirmation
  • βœ… Invitation-based registration
  • βœ… Token Blacklist (NEW in v1.2.0 ✨)
    • Immediate token invalidation on logout
    • "Logout all devices" functionality
    • Database-backed with automatic cleanup
    • Background cleanup service (hourly)
    • Works across load-balanced servers
    • Proper logout that actually works!
  • βœ… Account Lockout (v1.1)
    • Automatic lockout after 5 failed attempts
    • 15-minute lockout duration (configurable)
    • Admin unlock capability
    • Full audit trail integration

Audit & Monitoring:

  • βœ… Comprehensive Audit Logging
    • Automatic change tracking for all entities
    • Old/new value capture
    • User and operation tracking
    • Duration and IP address logging
    • Separate audit database (HIPAA requirement)
  • βœ… Structured logging with Serilog
  • βœ… Security event tracking

API Protection:

  • βœ… Rate limiting (AspNetCoreRateLimit)
    • Login: 5 attempts per 15 minutes
    • Registration: 3 per hour
    • General API: 100 per minute
  • βœ… IP-based rate limiting
  • βœ… Configurable per-endpoint limits
  • βœ… IP whitelist support

Configuration Security:

  • βœ… User Secrets (Development)
  • βœ… Environment Variables (Production)
  • βœ… Azure Key Vault ready
  • βœ… Secrets generator tool
  • βœ… Configurable Identity Settings
    • Lockout policy via appsettings.json
    • Password requirements configurable
    • Environment-specific overrides

Transport Security:

  • βœ… HTTPS enforcement
  • βœ… HSTS headers
  • βœ… CORS configuration
  • βœ… Secure WebSocket (SignalR)

Session Management:

  • βœ… Single/Multiple/Limited session modes
  • βœ… Multi-device tracking
  • βœ… Logout current device (with blacklist)
  • βœ… Logout all devices (with blacklist)
  • βœ… Session info endpoint
🚧 In Progress (18%)

Priority 2 (P2):

  • Two-Factor Authentication (2FA) - TOTP-based additional security layer
  • Input Sanitization - Enhanced XSS protection with HtmlSanitizer
  • Security Headers - CSP, X-Frame-Options, X-Content-Type-Options, HSTS

Priority 3 (P3):

  • Encryption at Rest - Database field encryption (HIPAA critical)
  • CSRF Protection - Anti-forgery tokens for state-changing operations

πŸ“Š Detailed Status: See docu/SECURITY_AUDIT.md

πŸ’¬ Real-time Features (SignalR)

  • βœ… Private messaging
  • βœ… Group chat
  • βœ… Online/offline status
  • βœ… Multi-device support
  • βœ… Typing indicators
  • βœ… System notifications
  • βœ… Auto-reconnection
  • βœ… JWT authentication

🎯 Application Features

  • βœ… User management (Identity framework)
  • βœ… Email invitation system
  • βœ… Global exception handling
  • βœ… Input validation (FluentValidation)
  • βœ… AutoMapper object mapping
  • βœ… MediatR CQRS pattern
  • βœ… Swagger/OpenAPI documentation
  • βœ… API versioning
  • βœ… Sample CRUD operations

πŸ“š Documentation

πŸš€ Getting Started

πŸ” Security

πŸ—„οΈ Database & Audit

πŸŽ“ Learning

🐳 Deployment


πŸ—οΈ Architecture

BizBox follows Clean Architecture (Onion Architecture) with clear separation of concerns:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           BizBox.API (Presentation)              β”‚
β”‚  β”œβ”€ Controllers (API Endpoints)                  β”‚
β”‚  β”œβ”€ Middleware (Authentication, rate limiting)   β”‚
β”‚  β”œβ”€ Hubs (SignalR)                              β”‚
β”‚  └─ Configurations (DI, services setup)         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚        BizBox.APPLICATION (Use Cases)            β”‚
β”‚  β”œβ”€ Commands (Write operations - CQRS)          β”‚
β”‚  β”œβ”€ Queries (Read operations - CQRS)            β”‚
β”‚  └─ Validators (FluentValidation)               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           BizBox.DOMAIN (Entities)               β”‚
β”‚  β”œβ”€ Entities (Core business objects)            β”‚
β”‚  β”œβ”€ Value Objects                               β”‚
β”‚  └─ Domain Interfaces (Contracts)               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      BizBox.PERSISTENCE (Data Access)            β”‚
β”‚  β”œβ”€ DbContext (EF Core contexts)                β”‚
β”‚  β”‚   β”œβ”€ ApplicationDbContext (Main data)        β”‚
β”‚  β”‚   └─ AuditDbContext (Audit logs)             β”‚
β”‚  β”œβ”€ Migrations (Database versions)              β”‚
β”‚  └─ Configurations (Entity configurations)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚        BizBox.SERVICES (Infrastructure)          β”‚
β”‚  β”œβ”€ TokenBlacklistService (Token invalidation)  β”‚
β”‚  β”œβ”€ EmailService (SMTP integration)             β”‚
β”‚  β”œβ”€ EncryptionService (AES-256 crypto)          β”‚
β”‚  β”œβ”€ CurrentUserService (User context)           β”‚
β”‚  └─ AuditCaptureService (Audit logging)         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ” Security

Defense-in-Depth Architecture

Layer 1: Rate Limiting (DDoS protection)
         ↓
Layer 2: HTTPS/TLS (Transport encryption)
         ↓
Layer 3: JWT Authentication (Identity)
         ↓
Layer 4: Token Blacklist (Logout validation) ← NEW!
         ↓
Layer 5: Token Versioning (Session security)
         ↓
Layer 6: Role Authorization (Access control)
         ↓
Layer 7: Ticket Validation (BOLA protection)
         ↓
Layer 8: Input Validation (Data integrity)
         ↓
Layer 9: Audit Logging (Monitoring & compliance)

HIPAA Compliance Status

Requirement Status Implementation
Access Control βœ… Complete Role-based, ticket validation, account lockout, token blacklist
Audit Controls βœ… Complete Comprehensive audit logging (separate database)
Person/Entity Authentication βœ… Complete JWT + email verification + lockout + proper logout
Transmission Security βœ… Complete HTTPS/TLS, encrypted JWT payloads (AES-256)
Integrity Controls 🚧 Partial Change tracking implemented, hash verification pending
Encryption at Rest ❌ Pending Database field encryption (P3 - Critical for PHI)

Current Score: 50% HIPAA Compliant (16/32 requirements)


πŸ“ Project Structure

BizBox.WebApi.Template/
β”‚
β”œβ”€β”€ BizBox.API/                          # 🌐 Presentation Layer
β”‚   β”œβ”€β”€ Controllers/
β”‚   β”‚   β”œβ”€β”€ AuthController.cs            # Authentication (+ new logout endpoints)
β”‚   β”‚   β”œβ”€β”€ UserController.cs
β”‚   β”‚   └── AuditLogController.cs
β”‚   └── Middleware/
β”‚       β”œβ”€β”€ TokenBlacklistMiddleware.cs  # Token blacklist validation (NEW)
β”‚       β”œβ”€β”€ TokenVersionValidationMiddleware.cs
β”‚       └── TicketValidationMiddleware.cs
β”‚
β”œβ”€β”€ BizBox.APPLICATION/                  # πŸ’Ό Application Layer
β”‚   └── Auth/
β”‚       └── Commands/
β”‚           β”œβ”€β”€ Logout.cs                # Logout command (NEW)
β”‚           └── LogoutAllDevices.cs      # Logout all devices (NEW)
β”‚
β”œβ”€β”€ BizBox.DOMAIN/                       # 🎯 Domain Layer
β”‚   β”œβ”€β”€ Entities/
β”‚   β”‚   β”œβ”€β”€ TokenBlacklist/
β”‚   β”‚   β”‚   └── TokenBlacklist.cs        # Token blacklist entity (NEW)
β”‚   β”‚   └── User/
β”‚   β”‚       └── ApplicationUser.cs
β”‚   └── Interfaces/
β”‚       └── ITokenBlacklistService.cs    # Token blacklist contract (NEW)
β”‚
β”œβ”€β”€ BizBox.PERSISTENCE/                  # πŸ—„οΈ Persistence Layer
β”‚   β”œβ”€β”€ Context/
β”‚   β”‚   β”œβ”€β”€ ApplicationDbContext.cs      # Main database (+ TokenBlacklist)
β”‚   β”‚   └── AuditDbContext.cs
β”‚   β”œβ”€β”€ Migrations/
β”‚   β”‚   β”œβ”€β”€ *_TokenBlacklist.cs          # Token blacklist migration (NEW)
β”‚   β”‚   └── Audit/
β”‚   └── Configurations/
β”‚       └── TokenBlacklistConfiguration.cs # EF config (NEW)
β”‚
└── BizBox.SERVICES/                     # βš™οΈ Infrastructure Layer
    └── TokenBlacklistService/           # (NEW)
        β”œβ”€β”€ DatabaseTokenBlacklistService.cs
        └── TokenBlacklistCleanupService.cs

πŸ› οΈ Development

Running Locally

# Development mode with watch
dotnet watch --project BizBox.API

# Run without watch
dotnet run --project BizBox.API

Database Migrations

# Main Database
dotnet ef migrations add MigrationName \
  --project BizBox.PERSISTENCE \
  --startup-project BizBox.API \
  --context ApplicationDbContext

# Audit Database
dotnet ef migrations add MigrationName \
  --project BizBox.PERSISTENCE \
  --startup-project BizBox.API \
  --context AuditDbContext \
  --output-dir Migrations/Audit

# Apply Migrations
dotnet ef database update --context ApplicationDbContext
dotnet ef database update --context AuditDbContext

πŸ“Š Version History

πŸŽ‰ Version 1.2.0 (Current - January 2025)

πŸš€ Major Feature: Token Blacklist

  • βœ… Proper Logout Functionality
    • Immediate token invalidation on logout
    • "Logout all devices" with bulk token blacklisting
    • Database-backed blacklist (PostgreSQL)
    • Token blacklist middleware (validates on every request)
    • Background cleanup service (removes expired tokens hourly)
    • Configurable cleanup interval and batch size
    • Works across load-balanced servers
    • No more "JWT tokens can't be revoked" problem!

New Endpoints:

  • POST /api/auth/logout-v2 - Logout from current device
  • POST /api/auth/logout-all-devices - Logout from all devices

Database Changes:

  • New TokenBlacklist table with performance indexes
  • Automatic migration included
  • Configurable via appsettings.json

Security & Compliance:

  • βœ… Security Score: 78% β†’ 82% (+4%)
  • βœ… HIPAA Compliance: 45% β†’ 50% (+5%)
  • βœ… Items Complete: 15/19 β†’ 16/19 security items

Documentation Added:

  • Complete Token Blacklist architecture documentation
  • Implementation guides and testing procedures
  • Updated README with new features

πŸ“¦ Version 1.1.0 (December 2024 - January 2025)

Major Features:

  • βœ… Comprehensive Audit Logging System
  • βœ… Account Lockout System (TESTED βœ“)
  • βœ… Configurable Identity Settings
  • βœ… 12-Factor App Methodology (12/12 complete)

Security:

  • Security Score: 60% β†’ 78% (+18%)
  • HIPAA Compliance: 30% β†’ 45% (+15%)
  • Items Complete: 13/19 β†’ 15/19

πŸ“¦ Version 1.0.0 (December 2024)

Initial Release:

  • JWT authentication & authorization
  • Rate limiting
  • SignalR real-time messaging
  • Session management
  • Clean architecture foundation
  • Published to NuGet

πŸ—ΊοΈ Roadmap

βœ… Version 1.2.0 (Current - January 2025)

  • βœ… Token Blacklist implementation
  • βœ… Proper logout functionality
  • βœ… "Logout all devices" support
  • βœ… Background cleanup service
  • βœ… 82% security completion
  • βœ… 50% HIPAA compliance

πŸ‘‰ Version 1.3.0 (Q1 2025) - Next Up

Priority 2 (P2) - High Security:

  • Two-Factor Authentication (2FA) (1-2 weeks)
    • TOTP-based implementation
    • QR code generation
    • Backup codes
  • Input Sanitization (1 week)
    • HtmlSanitizer integration
    • XSS protection
    • Content Security Policy headers
  • Security Headers (2-3 days)
    • CSP, X-Frame-Options, X-Content-Type-Options
    • HSTS configuration

Expected Metrics:

  • Security Score: 82% β†’ 90%
  • HIPAA Compliance: 50% β†’ 70%
  • Items Complete: 16/19 β†’ 18/19

πŸ“‹ Version 2.0 (Q2-Q3 2025)

  • Encryption at rest (field-level)
  • Full HIPAA compliance (95%+)
  • OAuth/OIDC integration
  • Advanced monitoring dashboard
  • SOC 2 compliance ready

🀝 Support & Contributing

Getting Help

Contributing

We welcome contributions! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Follow our coding standards
  4. Write/update tests
  5. Update documentation
  6. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License.


<div align="center">

Made with ❀️ and πŸ” by the BizBox Team

⭐ Star us on GitHub if this template helps your project!

πŸ›‘οΈ Security First. HIPAA Ready. Production Proven.

v1.2.0 - Now with Proper Logout! πŸŽ‰

</div>

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.6.0 170 2/12/2026
1.5.0 156 2/12/2026
1.2.0 204 1/7/2026
1.0.0 346 10/21/2025

Version 1.2.0 - Token Blacklist Release (82% Security Complete)

🎉 MAJOR NEW FEATURE:
β€’ Token Blacklist - Proper logout functionality that actually works!
 - Immediate token invalidation on logout
 - "Logout all devices" functionality
 - Database-backed with automatic cleanup
 - Background cleanup service (hourly)
 - Works across load-balanced servers
 - No more "JWT tokens can't be revoked" problem

βœ… COMPLETED SECURITY FEATURES (16/19):
β€’ JWT Authentication with HS256/RS256 and encrypted payloads (AES-256)
β€’ Token Blacklist with automatic cleanup (NEW - v1.2.0)
β€’ Account Lockout (5 failed attempts, 15-min lockout) (v1.1.0)
β€’ Comprehensive Audit Logging with separate database (v1.1.0)
β€’ Token versioning for session management
β€’ Encrypted ticket system (BOLA/IDOR protection)
β€’ Rate limiting with AspNetCoreRateLimit
β€’ Secrets management (User Secrets, Environment Variables, Key Vault ready)
β€’ Session management (Single/Multiple/Limited modes)
β€’ Role-based authorization (Admin, SuperAdmin, Finance)
β€’ HTTPS enforcement with HSTS
β€’ CORS configuration
β€’ Password security with PBKDF2
β€’ SignalR with JWT authentication
β€’ Configurable identity settings

📈 METRICS:
β€’ Security Score: 82% Complete (16/19 items)
β€’ HIPAA Compliance: 50% Complete
β€’ Production Ready: βœ… Yes

🏗️ ARCHITECTURE:
β€’ Clean Architecture (5 layers)
β€’ CQRS pattern with MediatR
β€’ Repository pattern with EF Core
β€’ PostgreSQL database (main + audit)
β€’ Background services

📚 FEATURES:
β€’ User management with ASP.NET Identity
β€’ Email invitation system
β€’ Multi-device session tracking
β€’ Proper logout (current device & all devices)
β€’ Real-time messaging (SignalR)
β€’ Comprehensive documentation
β€’ Swagger/OpenAPI
β€’ Migration files included
β€’ Secrets generator script

🚧 COMING IN v1.3 (Target: 90% Security):
β€’ Two-Factor Authentication (2FA)
β€’ Input Sanitization (XSS protection)
β€’ Security Headers (CSP, X-Frame-Options)
β€’ CSRF Protection

📦 WHAT'S INCLUDED:
β€’ Complete source code with migrations
β€’ Token blacklist implementation
β€’ Audit logging system
β€’ Account lockout system
β€’ Generate-Secrets scripts (.bat & .ps1)
β€’ Comprehensive documentation (12 guides)
β€’ Test controllers for debugging
β€’ Sample implementations