A lightweight, robust microservice built with FastAPI to manually generate and verify JSON Web Tokens (JWT) using EdDSA (Ed25519) cryptographic signatures.
- EdDSA (Ed25519) Signatures: High-security, high-performance asymmetric cryptographic keys.
- FastAPI Core: Fast, modern API with automatic JSON Schema and interactive documentation via Swagger UI.
- JWKS Endpoint: Dynamically expose your public key via the
/api/auth/jwksroute. - Docker Ready: Fully containerized using multi-stage builds and best security practices.
- Professional Structure: Scalable layout with separated
core,api, andschemas.
- Docker & Docker Compose
- Optional: Python 3.12+ if running locally on your hardware.
If using Docker: You are securely set! The Dockerfile automatically generates a fresh, container-scoped getJwt Ed25519 keypair safely inside the container during the build process, isolating it from your local system.
If running locally (without Docker): This application expects an Ed25519 SSH keypair (getJwt and getJwt.pub) located in the root directory. You can generate them by running:
ssh-keygen -t ed25519 -f ./getJwt -N "" -q(The .gitignore is already configured to prevent these from being checked into version control).
Development Environment (with live code reloading):
docker compose up --buildProduction Environment (uses Uvicorn workers, restarts automatically, and does not mount source code dynamically):
docker compose -f docker-compose.prod.yml up --build -d- Create a virtual environment:
python -m venv .venv - Activate the virtual environment:
- Windows:
.venv\Scripts\activate - Linux/Mac:
source .venv/bin/activate
- Windows:
- Install dependencies:
pip install -r requirements.txt - Set up environment variables by creating a
.envfile in the root directory:APP_URL=http://localhost:8000
- Run the development server:
uvicorn app.main:app --reload
getJwt/
├── app/
│ ├── main.py # The entry point of the application
│ ├── api/ # API routes
│ │ └── v1/auth.py # Auth endpoints
│ ├── core/ # Core configurations and cryptography logic
│ └── schemas/ # Pydantic schemas (TokenRequest, VerifyRequest)
├── tests/ # Pytest suite
└── ...
Once the application starts, navigate to the interactive OpenAPI docs:
➡ http://localhost:8000/docs
GET /: Health-check endpoint.GET /api/auth/jwks: Returns the JSON Web Key Set (JWKS), useful for other clients and microservices that need to verify your tokens independently.POST /generate-token: Takes a JSONpayloadand anexpires_in_hoursvalue to cryptographically sign and return a new JWT.POST /verify-token: Takes thetokenand thexcomponent of your public key. Decodes and verifies the signature and expiration timestamp.
To run the automated tests via pytest:
- Activate your virtual environment (
.venv\Scripts\activateorsource .venv/bin/activate). - Install test dependencies:
pip install -r requirements-dev.txt - Run tests natively:
pytest
- The
Dockerfilecreates a non-root User (appuser) to ensure the container acts with least-privilege principles. - Private keys are granted strict Linux file permissions (
600) within the Docker image. - For enterprise-grade production, it's recommended to mount your keys into the production container dynamically (e.g. through Docker Secrets or read-only volume mounts) rather than building them into the image using
COPY.
We welcome contributions to this project! Please see the CONTRIBUTING.md file for instructions on how to set up the development environment, guidelines on submitting code, and details on our PR process.