Skip to content

intfloatbool/auth-api-minimal-dotnet

Repository files navigation

Auth API (ASP.NET Minimal API)

🇷🇺 Russian version

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.


✨ Features

  • 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

📂 Project structure

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

🚀 Quick start

Locally (dotnet run)

cd src/AuthApi
dotnet run

API will be available at: http://localhost:5000

In Docker

docker build -t auth-api .
docker run -p 5000:5000 auth-api

Or via docker-compose:

docker-compose up --build

🔑 Endpoints

POST /register

Register a new user.
Example request:

{
  "username": "test",
  "password": "123456"
}

POST /login

Authenticate and receive tokens.
Example response:

{
  "accessToken": "<jwt-token>",
  "refreshToken": "<guid>"
}

POST /refresh

Get a new access token using a refresh token.


⚙️ Configuration

Main settings are in appsettings.json:

  • JWT (issuer, audience, key)
  • Access/refresh token lifetimes

🛠 Tech stack

About

Auth API with ASP.NET Minimal API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published