Skip to content

KenjiAu-Creator/jwt-Auth-SpringBoot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JWT Authentication with Spring Boot Java Spring Boot PostgreSQL

A lightweight Spring Boot application demonstrating JWT-based authentication for REST APIs.


Features

  • User registration & login
  • JWT token generation & validation
  • Secured REST endpoints
  • PostgreSQL integration
  • Role-based access control (optional)

Setup

1. Clone the repo

git clone https://github.com/your-username/your-repo-name.git
cd your-repo-name

2. Configure database

  • Run PostgreSQL locally or via Docker:
docker run --name local-postgres \
  -e POSTGRES_USER=myuser \
  -e POSTGRES_PASSWORD=mypassword \
  -e POSTGRES_DB=jwt-security \
  -p 5432:5432 \
  -d postgres:16
  • Add credentials to environment variables instead of committing application.yml:
export DB_USER=myuser
export DB_PASS=mypassword
export DB_NAME=jwt-security
export DB_HOST=localhost

3. Build & Run

Maven

mvn clean install
mvn spring-boot:run

Gradle

./gradlew build
./gradlew bootRun

API Examples

Register a new user

POST /auth/register
Content-Type: application/json

{
  "username": "testuser",
  "password": "password123"
}

Login to get JWT

POST /auth/login
Content-Type: application/json

{
  "username": "testuser",
  "password": "password123"
}

Access secured endpoint

GET /api/secure
Authorization: Bearer <your-jwt-token>

Security Notes

  • Do not commit application.yml with credentials — add it to .gitignore.
  • Use environment variables or external config for secrets.
  • Consider a secrets manager (e.g., Vault) in production.

License

MIT License — see LICENSE for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages