This project is an authentication microservice based on .NET 9.
- JWT-based authentication
- User management
- Advanced configuration options
- Modern .NET 9 architecture
- Pagination support
- Secure password management with hashing
- Multiple DbContext and UnitOfWork infrastructure
- Centralized log management with Elasticsearch & Kibana
- .NET 9 SDK
- SQL Server (or a compatible database)
- Docker (for Elasticsearch, Kibana, and SQL Server containers)
- Clone the repository:
- Restore dependencies:
-
Configure environment variables for Docker:
- Copy
.env.exampleto.envand fill in the required values:
cp .env.example .env
- Never commit the
.envfile to version control.
- Copy
-
Start all services with Docker:
docker compose up -d
-
Initialize User Secrets (run this once if you are using it for the first time to securely store sensitive data in the development environment):
dotnet user-secrets init --project src/Presentation/MediatorAuthService.Api
-
Set the required secrets:
dotnet user-secrets set "ConnectionStrings:Default" "<CONNECTION_STRING>" --project src/Presentation/MediatorAuthService.Api dotnet user-secrets set "JwtTokenOption:SecurityKey" "<SECURITY_KEY>" --project src/Presentation/MediatorAuthService.Api dotnet user-secrets set "ElasticSearch:Uri" "http://localhost:9200" --project src/Presentation/MediatorAuthService.Api dotnet user-secrets set "MediatR:LicenseKey" "<LICENSE_KEY>" --project src/Presentation/MediatorAuthService.Api
For more information, see User Secrets.
-
Run the application:
Note: When the application starts for the first time, the database and required tables will be created automatically thanks to the
app.ApplyMigration();operation. There is no need for an extra migration or manual database creation step.
- All configurations are managed via the
appsettings.jsonfile or environment variables. - Do not store sensitive information such as connection strings directly in
appsettings.json. - For Docker-based deployments, use the
.envfile (see.env.example).
This project uses Serilog with Elasticsearch as the log sink. All application logs are shipped to Elasticsearch and can be visualized via Kibana.
- Kibana UI:
http://localhost:5601 - Elasticsearch:
http://localhost:9200
Log levels are configured per namespace in appsettings.json:
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"Microsoft.EntityFrameworkCore": "Warning",
"System": "Warning"
}
}
}Note: Elasticsearch requires
vm.max_map_countto be at least262144. On Windows with WSL2, run the following command as administrator:wsl -d docker-desktop sysctl -w vm.max_map_count=262144
src/Presentation/MediatorAuthService.Api: API projectsrc/Application: Application layersrc/Domain: Domain models and rulessrc/Infrastructure: Data access and infrastructure layer
- .NET 9 – Application infrastructure and API development
- ASP.NET Core – Web API and middleware architecture
- Entity Framework Core – ORM and database operations
- JWT (JSON Web Token) – Authentication and authorization
- User Secrets – Secure secret management in development
- Dependency Injection – Dependency management
- Automapper – Object mapping
- FluentValidation – Model validation
- Swagger / Swashbuckle – API documentation
- MediatR – CQRS and mediator pattern
- API Versioning (Microsoft.AspNetCore.Mvc.Versioning) – API version management
- Pagination – Efficient data listing for large datasets
- Hashing – Secure password storage and verification
- Multiple DbContext & UnitOfWork – Integrated transaction management with multiple DbContexts
- Docker – Containerization and deployment
- Serilog – Structured logging
- Elasticsearch – Centralized log storage and search
- Kibana – Log visualization and monitoring dashboard
This project supports API versioning using the Microsoft.AspNetCore.Mvc.Versioning package.
By default, versioning is done via URL segment:
/api/v1/Auth
To add a new version, you can add an attribute like [ApiVersion("2.0")] to your controller.
This project is licensed under the MIT License.