A microservice-based User Management API built with ASP.NET Core 9 in C#. This API is designed for plug-and-play user authentication and role-based access control (RBAC), supporting PostgreSQL 17 as the database engine.
This project is currently developed on macOS, but it can be set up on Windows and Linux as well.
- Prerequisites
- Getting Started
- Configuration
- Running Database Migrations
- Running the API
- Development
- Testing
- Contributing
- License
Before running this API, ensure you have the following installed:
-
.NET 9 SDK
- Download and install from the official .NET website.
- Verify installation:
dotnet --version
-
PostgreSQL 17
- macOS (using Homebrew):
brew install postgresql@17
- Ubuntu/Debian:
sudo apt update sudo apt install postgresql postgresql-contrib
- Windows:
- Download and install from PostgreSQL website.
- macOS (using Homebrew):
-
Entity Framework Core CLI
If not already installed, run:dotnet tool install --global dotnet-ef
-
An IDE or Editor
- Recommended: Visual Studio Code, JetBrains Rider, or Visual Studio.
Follow these steps to set up the project:
git clone https://github.com/KuyeselaOrganization/UserManagementAPI.git
cd UserManagementAPI
dotnet restore
- macOS:
brew services start postgresql@17
- Ubuntu/Debian:
sudo systemctl start postgresql
Run the following command to create a new database for the API:
psql -U your_username -c "CREATE DATABASE kuyeselaUserDb;"
Replace your_username
with your PostgreSQL username.
Run the following command to copy the default settings:
cp appsettings.json.example appsettings.json
cp appsettings.Development.json.example appsettings.Development.json
If appsettings.json.example
does not exist, manually create appsettings.json
.
Open appsettings.json
and update the connection string to match your PostgreSQL credentials:
{
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Port=5432;Database=usermanagement;Username=your_username;Password=your_password"
},
"JwtSettings": {
"Secret": "YOUR_SECRET_KEY",
"Issuer": "UserManagementService",
"Audience": "UserManagementClients",
"ExpiryMinutes": 60
}
}
Replace:
your_username
→ Your PostgreSQL username.your_password
→ Your PostgreSQL password.
Before running the API, apply database migrations:
dotnet ef database update
If you encounter an error "dotnet ef
not found", install EF Core CLI using:
dotnet tool install --global dotnet-ef
Developers or engineers who would like to add a migrations file can run the following command:
dotnet ef migrations add MigrationName
On startup, the system automatically creates an "Administrator" role and a default admin user:
- Admin Email:
[email protected]
- Admin Password:
Admin@123
After running migrations, you can log in with these credentials.
To start the API locally, run:
dotnet run
Once the server is running, you can access the API at:
- HTTP:
http://localhost:5003
- HTTPS:
https://localhost:7022
To explore available API endpoints using Swagger, navigate to:
http://localhost:5003/swagger
For automatic code updates while running:
dotnet watch run
If you need to start over, reset the database:
dotnet ef database drop
dotnet ef database update
The project includes unit tests to validate the API's functionality.
To run tests:
dotnet test
Contributions are welcome! 🚀 If you’d like to improve this project:
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to your fork
- Open a pull request
Please follow the project's coding style and ensure all tests pass before submitting changes.
This project is licensed under the MIT License. See LICENSE
for more details.