AccountService is a .NET Core microservice for handling user account management, authentication, and security monitoring as part of the MicroNetHub ecosystem.
- Complete Account Management: Create, read, update, and delete user accounts
- Authentication: JWT-based authentication with refresh tokens
- OAuth Integration: Google authentication support
- Security Monitoring: Track login attempts, password changes, and other security events
- Access Logging: Record user access details (IP address, device, location)
- Role-based Authorization: Admin and User role differentiation
- API Documentation: Swagger integration for easy API exploration
- Health Checks: Database connectivity monitoring
- Framework: ASP.NET Core
- Database: MySQL with Entity Framework Core
- Authentication: JWT Bearer Authentication
- API Documentation: Swagger/OpenAPI
- ORM: Entity Framework Core with Code-First approach
AccountService/
├── AccountService.API/ # API controllers and startup configuration
├── AccountService.Core/ # Business logic, services, and domain models
│ ├── Entities/ # Domain entities
│ ├── Interfaces/ # Service and repository interfaces
│ └── Services/ # Service implementations
├── AccountService.Infrastructure/# Data access implementation
│ ├── Data/ # Database context and migrations
│ └── Repositories/ # Repository implementations
└── AccountService.Shared/ # DTOs and shared models
- .NET 8.0 SDK
- MySQL Server 8.0 or later
- Git
git clone https://github.com/YourUsername/MicroNetHub.git
cd MicroNetHub/AccountService# Restore all project dependencies
dotnet restoreUpdate the connection string in AccountService.API/appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "server=localhost;port=3306;database=micronet_account;user=root;password=your_password"
},
"Jwt": {
"Secret": "YourSecretKeyHere_MakeItLongAndComplex_AtLeast32Characters",
"ExpiryMinutes": 60,
"Issuer": "MicroNetHub",
"Audience": "MicroNetHub"
}
}Ensure your MySQL server is running, then create the database:
CREATE DATABASE micronet_account;Install the EF Core tools (if not already installed):
dotnet tool install --global dotnet-efApply the migrations to create the database schema:
# Navigate to the API project directory
cd AccountService.API
# Apply existing migrations
dotnet ef database update --project ../AccountService.Infrastructure/AccountService.Infrastructure.csprojdotnet runThe application will automatically:
- Connect to the MySQL database
- Apply any pending migrations
- Seed initial data (admin account)
- Start the API service
You can access the Swagger UI at: https://localhost:5001/swagger
The application is configured to automatically apply migrations at startup, but you can also manage them manually:
# List existing migrations
dotnet ef migrations list --project ../AccountService.Infrastructure/AccountService.Infrastructure.csproj
# Remove the last migration (if not applied to database)
dotnet ef migrations remove --project ../AccountService.Infrastructure/AccountService.Infrastructure.csproj
# Generate SQL script for migrations
dotnet ef migrations script --output migration.sql --project ../AccountService.Infrastructure/AccountService.Infrastructure.csprojPOST /api/auth/register- Register a new userPOST /api/auth/login- Login with email and passwordPOST /api/auth/google-login- Login with GooglePOST /api/auth/refresh-token- Refresh the authentication tokenPOST /api/auth/logout- Logout (requires authentication)POST /api/auth/change-password- Change password (requires authentication)
GET /api/accounts- Get all accounts (admin only)GET /api/accounts/{id}- Get account by IDPUT /api/accounts/{id}- Update accountDELETE /api/accounts/{id}- Delete accountGET /api/accounts/{id}/security-events- Get security events for an accountGET /api/accounts/{id}/access-logs- Get access logs for an accountPOST /api/accounts/{id}/access-logs- Add access log for an account
GET /health- Check service health status
- JWT authentication with configurable expiry
- Password hashing (implementation required in AccountService)
- Role-based access control
- IP and device tracking for security monitoring