Skip to content

IncridableAcuman/jwt-authentication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” JWT Authentication System

A secure and scalable JWT Authentication System built with Spring Boot, Spring Security, PostgreSQL, and JWT (JSON Web Token).

πŸš€ Features

  • User Registration
  • User Login
  • JWT Access Token Authentication
  • Refresh Token Support
  • Role-Based Authorization (USER / ADMIN)
  • Password Encryption with BCrypt
  • Spring Security Integration
  • PostgreSQL Database
  • Global Exception Handling
  • Request Validation
  • RESTful API Architecture

πŸ› οΈ Tech Stack

Backend

  • Java 21
  • Spring Boot 3
  • Spring Security
  • Spring Data JPA
  • JWT (JSON Web Token)
  • PostgreSQL
  • Lombok
  • Maven / Gradle

Security

  • Access Token
  • Refresh Token
  • BCrypt Password Hashing
  • Stateless Authentication

πŸ“‚ Project Structure

src
β”œβ”€β”€ config
β”œβ”€β”€ controller
β”œβ”€β”€ dto
β”œβ”€β”€ entity
β”œβ”€β”€ exception
β”œβ”€β”€ repository
β”œβ”€β”€ security
β”œβ”€β”€ service
└── util

βš™οΈ Installation

1. Clone Repository

git clone https://github.com/IncridableAcuman/jwt-authentication.git
cd jwt-authentication

2. Configure Database

Update your application.yml or application.properties:

spring.datasource.url=jdbc:postgresql://localhost:5432/jwt_auth
spring.datasource.username=postgres
spring.datasource.password=password

3. Configure JWT Secret

jwt.secret=your-secret-key
jwt.access-expiration=900000
jwt.refresh-expiration=604800000

4. Run Application

Maven

mvn spring-boot:run

Gradle

./gradlew bootRun

πŸ”‘ Authentication Flow

Registration

POST /api/auth/register

Request:

{
  "username": "john",
  "email": "john@example.com",
  "password": "password123"
}

Login

POST /api/auth/login

Request:

{
  "email": "john@example.com",
  "password": "password123"
}

Response:

{
  "accessToken": "jwt-access-token",
  "refreshToken": "jwt-refresh-token"
}

Refresh Token

POST /api/auth/refresh

Request:

{
  "refreshToken": "jwt-refresh-token"
}

πŸ”’ Protected Endpoint Example

GET /api/users/profile

Header:

Authorization: Bearer <access_token>

πŸ“œ API Endpoints

Method Endpoint Description
POST /api/auth/register Register User
POST /api/auth/login Login User
POST /api/auth/refresh Refresh Access Token
GET /api/users/profile Get User Profile
GET /api/admin/dashboard Admin Access

πŸ§ͺ Testing

Run tests using:

mvn test

or

./gradlew test

πŸ” Security Considerations

  • Passwords are encrypted using BCrypt.
  • Access Tokens are short-lived.
  • Refresh Tokens are stored securely.
  • Authentication is fully stateless.
  • Spring Security protects secured endpoints.

πŸ“ˆ Future Improvements

  • Email Verification
  • Password Reset
  • Two-Factor Authentication (2FA)
  • OAuth2 (Google / GitHub)
  • Docker Support
  • Redis Token Blacklist

🀝 Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss the proposed changes.


πŸ“„ License

This project is licensed under the MIT License.


πŸ‘¨β€πŸ’» Author

Developed by Izzat Abdusharipov

About

πŸ” JWT Authentication System A secure and scalable JWT Authentication System built with Spring Boot, Spring Security, PostgreSQL, and JWT (JSON Web Token).

Topics

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages