https://github.com/joegasewicz/spring-jwt-security
A lightweight JWT authentication library for Spring Boot
https://github.com/joegasewicz/spring-jwt-security
Last synced: 9 days ago
JSON representation
A lightweight JWT authentication library for Spring Boot
- Host: GitHub
- URL: https://github.com/joegasewicz/spring-jwt-security
- Owner: joegasewicz
- License: mit
- Created: 2025-08-02T16:21:31.000Z (2 months ago)
- Default Branch: master
- Last Pushed: 2025-08-02T16:35:36.000Z (2 months ago)
- Last Synced: 2025-08-02T18:35:00.845Z (2 months ago)
- Language: Java
- Size: 8.79 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🌐 spring-jwt-security
A lightweight JWT authentication library for Spring Boot. Easily secure your REST endpoints using the `@AuthRequired` annotation and decode JWT tokens without boilerplate.
## 🔧 Features
* ✅ `@AuthRequired` annotation to protect controller methods
* ✅ AOP-powered JWT verification
* ✅ Token creation & decoding via `JwtService`
* ✅ Externalized secret config via `application.properties`
* ✅ Auto-configuration via `JwtAutoConfiguration`---
## 📦 Installation
In your consuming Spring Boot project, add the local dependency:
```xml
digital.josef.jwtsecurity
spring-jwt-security
1.0-SNAPSHOT```
> **Note:** Until published to a Maven repository, install the JAR locally with:
>
> ```bash
> mvn install
> ```---
## ⚙️ Configuration
Add your JWT secret in `application.properties`:
```properties
jwt.secret=my_very_secret_key
```---
## 🔐 Protect Endpoints
Annotate controller methods with `@AuthRequired`:
```java
@RestController
@RequestMapping("/api/v1")
public class UserController {@GetMapping("/secure")
@AuthRequired
public String secureEndpoint() {
return "Protected content";
}
}
```---
## 🔑 Generate Tokens
Use the provided `JwtService`:
```java
@Autowired
private JwtService jwtService;@PostMapping("/login")
public ResponseEntity> login(@RequestBody LoginRequest request) {
Map claims = JwtService.generateClaims("user-id");
String token = jwtService.generateToken(claims, request.getEmail());return ResponseEntity.ok(Map.of("token", token));
}
```---
## 📜 License
MIT
---
## 👤 Author
Built by [josef.digital](https://josef.digital)