Sign inSign up

junjiewu0/jwt-auth-server

By junjiewu0

•Updated over 1 year ago

Simple JWT authentication server built with Spring Boot.

Image
0

434

junjiewu0/jwt-auth-server repository overview

⁠JWT Authentication Server

Java Version Spring Boot JWT Docker

A Simple JWT authentication server built with Spring Boot.

Available as a Docker image⁠.

Source code: https://github.com/junjie-w/jwt-auth-server⁠

⁠API Reference

EndpointMethodDescriptionAuthorization
/GETAPI info and available endpointsPublic
/api/healthGETService health checkPublic
/api/auth/registerPOSTRegister a new userPublic
/api/auth/loginPOSTAuthenticate and receive JWTPublic
/api/users/meGETGet authenticated user infoJWT 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  

Tag summary

Content type

Image

Digest

sha256:0273acd79…

Size

144.5 MB

Last updated

over 1 year ago

docker pull junjiewu0/jwt-auth-server