Developed by: Ans Abdullah Malik
A production-ready, full-stack Authentication and Authorization system architected with .NET 9 and Angular. This solution provides a secure, decoupled foundation for identity management using JWT (JSON Web Tokens) and Role-Based Access Control (RBAC), migrated from in-memory storage to a persistent SQL Server database using Entity Framework Core.
- Clean Architecture: Implements a strictly decoupled layered architecture (Core, Infrastructure, API) to ensure maintainability, testability, and separation of concerns.
- Secure Authentication: Features a stateless JWT implementation with custom claims, secure signing, and expiration handling.
- Role-Based Access Control (RBAC): granular permission management system distinguishing between standard Users and Administrators.
- Persistent Storage: Fully integrated with SQL Server using Entity Framework Core 9.0, replacing previous in-memory implementations for production reliability.
- Result Pattern: Utilizes a generic Result wrapper for consistent error handling and API response standardization.
- CORS Configuration: Securely configured Cross-Origin Resource Sharing to facilitate seamless communication between the Angular SPA and .NET Web API.
- .NET 9 SDK (C# 13)
- ASP.NET Core Web API
- Entity Framework Core 9.0 (Code-First approach)
- SQL Server (Relational Database)
- Swagger/OpenAPI (API Documentation)
- Angular (Single Page Application)
- TypeScript
- Bootstrap 5 (Responsive UI)
- RxJS (Reactive Extensions for state management)
The solution adheres to clean architecture principles:
src/ ├── Auth.Api/ # Application entry point, Controllers, and DI Configuration ├── Auth.Core/ # Domain Entities, Interfaces, and shared Result logic ├── Auth.Infrastructure/ # Database Context, EF Core Migrations, and Repository implementations └── Auth.Frontend/ # Angular Client Application
Follow these instructions to set up the project locally for development and testing.
- .NET SDK 9.0
- Node.js (LTS version)
- SQL Server (Express, Developer, or LocalDB)
- Clone the repository.
- Navigate to the API directory: cd src/Auth.Api
- Configure the database connection string in
appsettings.jsonto point to your local SQL Server instance. - Apply database migrations to create the schema: dotnet ef database update --project ../Auth.Infrastructure
- Start the API: dotnet run
The API will initialize and listen on the configured local port (e.g., http://localhost:5166).
- Navigate to the frontend directory: cd ../Auth.Frontend
- Install dependencies: npm install
- Launch the application: ng serve --open
The application will automatically open in your default browser at http://localhost:4200.
- Swagger UI: Access the interactive API documentation at
/swaggeron the API port. - Registration: Use the
/registerroute on the frontend to create a new user entity. - Persistence Check: Verify data integrity by querying the
Userstable in SQL Server after restarting the application. - Authentication: Log in with valid credentials to receive a JWT and access protected routes on the dashboard.
- JWT Secret: The
Jwt:Keyinappsettings.jsonis a placeholder for development environments. For production deployment, ensure this is replaced with a secure, high-entropy key managed via environment variables or a secrets manager. - CORS: The current configuration explicitly trusts
localhost:4200. Update theCORS:urlssetting inappsettings.jsonto reflect your production client domain.
Contributions are welcome. Please fork the repository and submit a Pull Request for review.
Distributed under the MIT License. See LICENSE.md for more information.