AuthServer là Web API xác thực người dùng viết bằng ASP.NET Core (.NET 10), dùng EF Core + SQL Server, hỗ trợ:
- Đăng ký tài khoản
- Đăng nhập và trả về JWT token
- Swagger để test API
- .NET SDK 10
- SQL Server (local hoặc remote)
- (Khuyến nghị) EF Core CLI:
dotnet tool install --global dotnet-efgit clone https://github.com/DucHoa1805/AuthServer.git
cd AuthServerFile chính: /home/runner/work/AuthServer/AuthServer/AuthServer/appsettings.json
Sửa ConnectionStrings:DefaultConnection theo máy của bạn:
"ConnectionStrings": {
"DefaultConnection": "Server=.;Database=AuthServerDb;Trusted_Connection=True;TrustServerCertificate=True"
}Điền Jwt:Key (không để rỗng). Ví dụ key đủ dài:
"Jwt": {
"Key": "your-very-strong-secret-key-at-least-32-characters",
"Issuer": "AuthServer",
"Audience": "AuthClient"
}dotnet ef database update --project AuthServer/AuthServer.csprojdotnet run --project AuthServer/AuthServer.csprojMặc định chạy ở:
http://localhost:5266https://localhost:7166
Swagger:
http://localhost:5266/swaggerhttps://localhost:7166/swagger
Base route: /api/auth
Đăng ký tài khoản mới.
Body mẫu:
{
"username": "testuser",
"email": "test@example.com",
"password": "Abcdef@123"
}Ràng buộc:
username: 3-20 ký tựemail: đúng định dạng emailpassword: tối thiểu 8 ký tự, có chữ hoa, chữ thường, số, ký tự đặc biệt (@$!%*?&)
Đăng nhập và nhận JWT token.
Body mẫu:
{
"username": "testuser",
"password": "Abcdef@123"
}Response mẫu:
{
"token": "<jwt-token>",
"username": "testuser"
}AuthServer/
├── Controllers/ # API endpoints
├── DTOs/ # Request models
├── Entities/ # Entity classes
├── Data/ # DbContext
├── Migrations/ # EF Core migrations
├── Properties/ # launchSettings
└── appsettings.json # cấu hình ứng dụng