A small learning project: authentication and authorization using C# ASP.NET Minimal API.
Implements JWT access/refresh tokens, user and refresh token storage in the database, and a simple architecture without unnecessary dependencies.
- User registration
- Authentication (issue of JWT access/refresh tokens)
- Refreshing access tokens using a refresh token
- Password hashing (base64 hasher as an example)
- Works with EF Core (InMemory or any SQL database)
- Dockerfile and docker-compose for containerized run
AuthApi/
├── src/AuthApi/ # Source code
│ ├── Endpoints/ # Routes (Register, Login, Refresh)
│ ├── Handlers/ # Request handlers
│ ├── Services/ # Tokens and password services
│ ├── Data/ # DbContexts for users and refresh tokens
│ ├── Models/ # User, RefreshToken
│ └── Program.cs # Entry point
├── docker-compose.yml
├── Dockerfile
└── run-dev.py # Local dev run
cd src/AuthApi
dotnet run
API will be available at: http://localhost:5000
docker build -t auth-api .
docker run -p 5000:5000 auth-api
Or via docker-compose:
docker-compose up --build
Register a new user.
Example request:
{
"username": "test",
"password": "123456"
}
Authenticate and receive tokens.
Example response:
{
"accessToken": "<jwt-token>",
"refreshToken": "<guid>"
}
Get a new access token using a refresh token.
Main settings are in appsettings.json
:
- JWT (issuer, audience, key)
- Access/refresh token lifetimes
- .NET 8
- ASP.NET Minimal API
- Entity Framework Core
- JWT
- Docker / docker-compose