BasicAuth is a .NET-based web API project implementing a basic authentication and user management system. It follows the CQRS (Command Query Responsibility Segregation) architectural pattern, separating read and write operations into distinct layers for better maintainability and scalability.
- User Authentication: JWT-based login and signup functionality
- User Management: CRUD operations for user accounts (Create, Read, Update, Delete), bulk imports for admins.
- Protected Endpoints: Endpoints accessible by admin roles
- API Documentation: Integrated Swagger UI for testing and exploring the API
- Framework: .NET 10.0
- Web Framework: ASP.NET Core
- Database: SQLite (with Entity Framework Core)
- Authentication: JWT Bearer Tokens
- Architecture: CQRS with MediatR
- API Documentation: Swashbuckle (Swagger)
- Environment Management: DotNetEnv for configuration
The solution is organized into multiple projects:
-
BasicAuth.Web: The main web API application
- Controllers for handling HTTP requests
- Program.cs for application configuration
- DTOs for API responses
- Migrations for database schema
-
BasicAuth.Commands: Handles write operations (commands)
- Auth commands (Login, Signup)
- User commands (Create, Update, Delete, Activate & Deactivate)
-
BasicAuth.Queries: Handles read operations (queries)
- User/UserInfo queries (GetUser, GetUsers)
- AdminDashboard query
-
BasicAuth.Data: Data access layer
- Entity Framework Core DbContext
- Database models (User entity)
-
BasicAuth.Services: Custom services
- Bulk imports of users
-
Prerequisites:
- .NET 10.0 SDK
- SQLite (included with EF Core)
-
Environment Setup:
- Create a
.envfile in theBasicAuth.Webdirectory with the following variables:DbConnection=Data Source=BasicAuth.db JWT_SECRET_KEY=your-secret-key-here X-Api-Key=your-api-ninjas-key-here
- Create a
-
Running the Application:
- Navigate to the
BasicAuth.Webdirectory - Run
dotnet runor use Visual Studio/VS Code to launch - The API will be available at
https://localhost:7140 - Swagger UI:
https://localhost:7140/swagger
- Navigate to the
-
Database Migration:
- The application automatically migrates the database on startup
- The project uses MediatR for implementing the CQRS pattern
- JWT tokens are required for accessing protected endpoints
- CORS is configured to allow requests from
https://localhost:7140 - Database migrations are handled automatically in development