Skip to content

An advanced .NET 8 template that uses TOTP-based multi-factor login with Otp.NET, EF Core (PostgreSQL), Docker, dotnet aspire, and Serilog—built around a Clean Architecture design. Perfect for learning or starting a secure project.

License

Notifications You must be signed in to change notification settings

mak-thevar/TotpCleanArch

Repository files navigation

Build Status Contributors Issues LinkedIn

TotpCleanArch

A .NET 8 web API template that demonstrates TOTP (Time-Based One-Time Password) multi-factor authentication with a Clean Architecture approach. It also integrates Entity Framework Core for data persistence and Serilog for advanced logging.

📋 Table of Contents

🏁 Getting Started

Prerequisites

🗃️ File Structure

├───.github
│   └───workflows
├───src
│   ├───TotpCleanArch.AppHost
│   ├───TotpCleanArch.Application
│   │   ├───Common
│   │   │   │   AppConstants.cs
│   │   │   └───Interfaces
│   │   │           IAuthService.cs
│   │   │           IQrCodeService.cs
│   │   │           ITotpService.cs
│   │   ├───Features
│   │   │   ├───QRCode
│   │   │   │   ├───Commands
│   │   │   │   └───Queries
│   │   │   ├───TOTP
│   │   │   │   ├───Commands
│   │   │   │   │       SetUpTotpCommand.cs
│   │   │   │   │       VerifyTotpCommand.cs
│   │   │   │   │
│   │   │   │   └───Queries
│   │   │   │           GetTotpSecretKeyQuery.cs
│   │   │   └───Users
│   │   │       ├───Commands
│   │   │       │       LoginCommand.cs
│   │   │       │       RegisterUserCommand.cs
│   │   │       │
│   │   │       ├───Models
│   │   │       │       UserDto.cs
│   │   │       │
│   │   │       └───Queries
│   │
│   ├───TotpCleanArch.Domain
│   │   ├───Entities
│   │   │       TotpSettings.cs
│   │   │       User.cs
│   ├───TotpCleanArch.Infrastructure
│   │   │   DependencyInjection.cs
│   │   ├───Persistence
│   │   │       ApplicationDbContext.cs
│   │   └───Services
│   │           AuthService.cs
│   │           QrCodeService.cs
│   │           TotpService.cs
│   │
│   ├───TotpCleanArch.ServiceDefaults
│   │   │   Extensions.cs
│   │
│   └───TotpCleanArch.WebApi
│       │   Program.cs
│       ├───Controllers
│       │       AuthController.cs
│       │       TotpController.cs
│       ├───Middlewares
│       │       GlobalExceptionHandlingMiddleware.cs
│
└───tests

Installation

  • Clone the repository
git clone https://github.com/mak-thevar/TotpCleanArch.git
  • Open the solution file 'TotpCleanArch.sln' directly in Visual Studio
  • Configure the Database The project automatically sets up a PostgreSQL container. You do not need to manually configure Postgres credentials in the API project files. Instead, you must store the Postgres username and password in the user-secrets file of TotpCleanArch.AppHost:
    {
    "Parameters:pg-password": "pg-password",
    "Parameters:pg-user": "pg-user"
    }
  • Now Build the project and run, Initially for the very first time it will create the database and will execute the migration scripts automatically.

✅ Features

  • Uses Serilog for stuctured logging.
  • Swagger for API documentation has been added.
  • Entityframework Core has been configured for database communication.
  • Otp.NET for generating and verifying T-Otp
  • Follows Clean Architecture - Separates the solution into Domain, Application, Infrastructure, and WebAPI layers.
  • Docker & dotnet Aspire - Containerize your application for easy deployment, plus integration with dotnet aspire.

🔘 Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📸 Screenshots

aspire-dashboard
Aspire Dashboard
register
User Registration
totp-setup
Setup TOTP
totp-verify
Verify TOTP

🎫 License

Distributed under the MIT License. See LICENSE for more information.

📱 Contact

About

An advanced .NET 8 template that uses TOTP-based multi-factor login with Otp.NET, EF Core (PostgreSQL), Docker, dotnet aspire, and Serilog—built around a Clean Architecture design. Perfect for learning or starting a secure project.

Topics

Resources

License

Stars

Watchers

Forks

Languages