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.
- Visual Studio OR Visual Studio Code
- Docker installed and running (required to run this project in a container).
├───.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
- 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.
- 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.
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.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
![]() |
---|
Aspire Dashboard |
![]() |
---|
User Registration |
![]() |
---|
Setup TOTP |
![]() |
---|
Verify TOTP |
Distributed under the MIT License. See LICENSE
for more information.
- Name: Muthukumar Thevar
- Email: mak.thevar@outlook.com
- Portfolio: https://mak-thevar.dev
- Project Link: https://github.com/mak-thevar/TotpCleanArch