Skip to content

junjie-w/jwt-auth-server

Repository files navigation

JWT Authentication Server

Java Version Spring Boot JWT Docker

A Simple JWT authentication server built with Spring Boot.

Available as a Docker image.

API Reference

Endpoint Method Description Authorization
/ GET API info and available endpoints Public
/api/health GET Service health check Public
/api/auth/register POST Register a new user Public
/api/auth/login POST Authenticate and receive JWT Public
/api/users/me GET Get authenticated user info JWT Required

Try all API endpoints with the included script:

./scripts/try_api.sh
Example API Requests

API Info

curl http://localhost:8080/

Health Check

curl http://localhost:8080/api/health

Register User

curl -X POST http://localhost:8080/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "username": "newuser",
    "email": "[email protected]",
    "password": "password123"
  }'

Login

curl -X POST http://localhost:8080/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "username": "newuser",
    "password": "password123"
  }'

Get Current User Info

curl -H "Authorization: Bearer JWT_TOKEN" \
  http://localhost:8080/api/users/me

Development Setup

# Clone repo
git clone https://github.com/junjie-w/jwt-auth-server.git
cd jwt-auth-server

# Run with development profile
make run-dev

Docker Usage

Pre-built Image from Docker Hub

# Pull image from Docker Hub
docker pull junjiewu0/jwt-auth-server

# For ARM-based machines (Apple Silicon, etc.)
docker pull --platform linux/amd64 junjiewu0/jwt-auth-server

# Run container
docker run -p 8080:8080 junjiewu0/jwt-auth-server 

# For ARM-based machines (Apple Silicon, etc.)
docker run --platform linux/amd64 -p 8080:8080 junjiewu0/jwt-auth-server

Build Image Locally

# Build image
docker build -t jwt-auth-server .

# Run container
docker run -p 8080:8080 jwt-auth-server

Run Tests

# Run all tests
make test

# Run a specific test class
make test-single class=UserServiceTest

# Run tests with verbose output
make test-verbose

Makefile Commands

make run                           # Start the application  
make run-dev                       # Start the application with the development profile  
make run-prod                      # Start the application with the production profile  
make build                         # Clean and build the application  
make clean                         # Remove all compiled files and build artifacts  
make test                          # Run all tests  
make test-single class=            # Run a specific test class 
make test-verbose                  # Run tests with detailed output  
make docker-build                  # Build the Docker image
make docker-run                    # Run container from local image
make docker-pull-remote            # Pull pre-built image from Docker Hub
make docker-run-remote             # Run container from pre-built Docker Hub image
make try-api                       # Execute the API testing script  

About

Simple JWT authentication server built with Spring Boot. Available as a Docker image.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published