Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

edinylcnn/dotnet-auth-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

11 Commits

Repository files navigation

dotnet-auth-api

A minimal, production-minded JWT authentication API built with .NET 9 Minimal API + EF Core 9 + MySQL + BCrypt + Swagger.

Designed for a Unity client, but generic enough for any client.


✨ Features

  • πŸ” Sign up & sign in: POST /auth/signup, POST /auth/login
  • πŸ†” Username & email availability: GET /auth/check-username, GET /auth/check-email
  • 🎫 JWT issuance on login and a protected endpoint: GET /users/me
  • πŸ”‘ Passwords stored as BCrypt salted hashes (never plaintext)
  • πŸ“– Swagger UI for quick testing
  • 🌐 CORS enabled (open in dev; restrict in prod)
  • πŸ—‚οΈ Clean structure with feature-based endpoint modules

πŸš€ Quick Start

Prerequisites

  • .NET 9 SDK
  • MySQL 8.0+

Configure (Development)

Update appsettings.Development.json with your local values:

{
 "ConnectionStrings": {
 "Default": "Server=localhost;Port=3306;Database=unity_auth_db;User=root;Password=CHANGEME;SslMode=None;"
 },
 "Jwt": {
 "Issuer": "DotnetAuthSample",
 "Audience": "DotnetAuthSample",
 "Key": "change-this-dev-key",
 "ExpiresMinutes": 60
 }
}

Production: never hardcode secrets. Provide them via environment variables (see Configuration).

Database (EF Core)

dotnet tool install --global dotnet-ef
dotnet add package Microsoft.EntityFrameworkCore.Design --version 9.*
dotnet ef migrations add InitialCreate
dotnet ef database update

Run

dotnet run

Open http://localhost:5042/swagger to test endpoints.

🧭 Endpoints (Overview)

  • GET /auth/check-username?username=edin β†’ { "exists": true|false, "message": "..." }
  • GET /auth/check-email?email=a@b.com β†’ { "exists": true|false, "message": "..." }
  • POST /auth/signup β†’ 201 Created | 409 Conflict
  • POST /auth/login β†’ 200 OK { token, username, email } | 401 Unauthorized
  • GET /users/me (JWT required) β†’ 200 { username, email } | 401 Unauthorized

For protected requests, send the header: Authorization: Bearer <JWT>


πŸ” Security

  • Passwords are BCrypt hashes (never store/log plaintext)
  • Use HTTPS in production
  • Add rate limiting / lockout for repeated failed logins
  • Rotating the JWT signing key invalidates existing tokens (plan key rotation if needed)

πŸ“œ License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /