Skip to content

Latest commit

 

History

History
89 lines (74 loc) · 4.12 KB

README.md

File metadata and controls

89 lines (74 loc) · 4.12 KB

SpringJWT

SpringJWT is a demo project designed to help developers understand how to implement JWT (JSON Web Token) authentication with Spring Security. This project showcases a backend solution using bearer tokens for secure authentication and includes a sample frontend for testing purposes.

Features

  • JWT Authentication: Secure user authentication using JWT bearer tokens.
  • Spring Security Integration: Leveraging Spring Security to manage user access.
  • Token Generation and Validation: Supports token issuance and validation with secure key management.
  • Sample Frontend: A basic frontend provided for testing authentication and secure routes.
  • Custom Exception Handling: Handles invalid credentials and other security exceptions.

Project Structure

src/
├── main/
│   ├── java/lk/ijse/jwt/
│   │   ├── config/
│   │   ├── controller/
│   │   ├── dto/
│   │   ├── entity/
│   │   ├── repository/
│   │   ├── service/
│   │   ├── util/
│   └── resources/
│       └── application.properties
└── templates/

How It Works

  1. JWT Token Generation: After successful login or registration, the backend generates a JWT token using user credentials.
  2. Token Validation: For secure routes, the token is validated to authenticate the user.
  3. Role-Based Authorization: Different user roles can access specific routes based on the token.
  4. Sample Frontend Testing: The frontend helps test login and authentication flow.

Requirements

  • Java 11+
  • Maven
  • Spring Boot
  • MySQL (or any compatible database)
  • Postman (for API testing)

Getting Started

1. Clone the repository

git clone https://github.com/gayanukabulegoda/SpringJWT.git

2. Configure the Application

Edit application.properties to set your MySQL connection details:

spring.datasource.url=jdbc:mysql://localhost:3306/springjwt
spring.datasource.username=YOUR_USERNAME
spring.datasource.password=YOUR_PASSWORD

3. Build and Run the Application

mvn clean install
mvn spring-boot:run

The backend will start running at http://localhost:8080.

4. Frontend Testing

The project includes a simple frontend to test JWT authentication.

5. API Documentation

Postman Documentation: API Documentation

License

This project is licensed under the MIT License - see the LICENSE file for details.


© 2024 Gayanuka Bulegoda