Skip to content

Lucas-aos/AuthApi

Repository files navigation

Auth API

Status .NET C# PostgreSQL JWT Swagger

A simple authentication API built with ASP.NET Core, JWT, Entity Framework Core, and PostgreSQL.

This project demonstrates how to implement token-based authentication, protect API routes, and document endpoints using Swagger/OpenAPI.


Features

  • User registration
  • User login with JWT generation
  • Token-based authentication
  • Protected endpoints using [Authorize]
  • PostgreSQL integration with Entity Framework Core
  • Interactive API documentation with Swagger

Technologies

  • ASP.NET Core Web API
  • C#
  • Entity Framework Core
  • PostgreSQL
  • JWT Authentication
  • Swagger / OpenAPI

Application Flow

Client > Controller > Service > Entity Framework Core > PostgreSQL

Project Structure

AuthApi
│
├── Controllers/
│   ├── AuthController.cs
│   └── UserController.cs
│
├── Data/
│   └── AppDbContext.cs
│
├── Models/
│   └── User.cs
│
├── Services/
│   └── JwtService.cs
│
└── Program.cs


API Endpoints

Authentication

Register User

POST /auth/register

Creates a new user.


Login

POST /auth/login

Returns a JWT token.


User

Get Profile

GET /user/profile

Returns information about the authenticated user.

Requires JWT token in the request header:

Authorization: Bearer {token}

Swagger Documentation

The API includes Swagger UI for easy testing and documentation.

Access it at:

http://localhost:xxxx/swagger

Screenshots

Swagger Interface

Swagger Interface

Authentication

Swagger Auth

Login

Swagger Login

Endpoint

Swagger EP


Running the Project

1 Clone the repository

git clone https://github.com/Lucas-aos/AuthApi.git

2 Navigate to the project folder

cd AuthApi

3 Configure the database

Update the connection string in:

appsettings.json

4 Run the project

dotnet run

5 Open Swagger

http://localhost:xxxx/swagger

Authentication Flow

  1. Register a new user
  2. Login to receive a JWT token
  3. Click Authorize in Swagger
  4. Paste the token
  5. Access protected endpoints

Learning Goals

This project was built to practice:

  • REST API development
  • JWT authentication
  • ASP.NET Core backend architecture
  • Database integration using EF Core
  • API documentation with Swagger

Author

Lucas Albuquerque

About

JWT Authentication API built with ASP.NET Core

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages