Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gayanukabulegoda/springjwt

SpringJWT is a simple project designed to help users understand JWT implementation with Spring Security, including the use of bearer tokens for secure authentication.
https://github.com/gayanukabulegoda/springjwt

authentication backend-auth bearer-token java-auth java-security jwt jwt-auth jwt-bearer-authentication jwt-token learn-security spring spring-authentication spring-boot spring-jwt spring-jwt-authentication spring-jwt-sample spring-security spring-security-jwt springjwt web-security

Last synced: about 1 month ago
JSON representation

SpringJWT is a simple project designed to help users understand JWT implementation with Spring Security, including the use of bearer tokens for secure authentication.

Awesome Lists containing this project

README

        

# 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
```bash
git clone https://github.com/gayanukabulegoda/SpringJWT.git
```
### 2. Configure the Application
Edit `application.properties` to set your MySQL connection details:
```bash
spring.datasource.url=jdbc:mysql://localhost:3306/springjwt
spring.datasource.username=YOUR_USERNAME
spring.datasource.password=YOUR_PASSWORD
```
### 3. Build and Run the Application
```bash
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](https://documenter.getpostman.com/view/36681432/2sAXqwXeJP)

## License
This project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.

##














© 2024 Gayanuka Bulegoda