An authentication service for Secure Chain tools, built with FastAPI. This service provides:
- User authentication: Registration, login, password management with JWT tokens
- API Key management: Service-to-service authentication for microservices
- Dual authentication: Support for both JWT (users) and API Keys (services)
- Database support: MongoDB for data storage and Neo4j for graph relationships
- 🔐 JWT-based authentication with access and refresh tokens
- 👤 User registration and login
- 🔑 Password change functionality
- 🚪 Logout with token revocation
- ✅ Token validation and account existence checks
- 🔑 Create API Keys for service-to-service authentication
- 📋 List all API Keys for a user
- ❌ Revoke API Keys
- ⏱️ Optional expiration dates
- 🔒 Secure key hashing with SHA-256
- Docker to deploy the tool.
- Docker Compose for container orchestration.
- It is recommended to use a GUI such as MongoDB Compass.
- Python 3.14 or higher.
- uv - Ultra-fast Python package manager (optional but recommended).
git clone https://github.com/securechaindev/securechain-auth.git
cd securechain-authCreate a .env file from the .env.template file and place it in the app/ directory. Modify the Json Web Token (JWT) secret key and algorithm with your own. You can generate your own secret key with the command openssl rand -base64 32.
Ensure you have the securechain Docker network created. If not, create it with:
docker network create securechainRun the command from the project root:
docker compose -f dev/docker-compose.yml up --buildThe API will be available at http://localhost:8001. You can access the API documentation at http://localhost:8001/docs.
Used by microservices for service-to-service communication:
# Create an API Key (requires JWT authentication)
# Then use API Key in other microservices
curl "https://securechain.dev/api/some_endpoint" -H "X-API-Key: sk_your_api_key_here"The project uses Python 3.14 and uv as the package manager for faster and more reliable dependency management.
-
Install uv (if not already installed):
curl -LsSf https://astral.sh/uv/install.sh | sh -
Create and activate a virtual environment:
uv venv source .venv/bin/activate -
Install dependencies:
uv sync
# Install test dependencies
uv sync --extra test
# Run all tests
uv run pytest
# Run tests with coverage report
uv run pytest --cov=app --cov-report=term-missing --cov-report=html
# Run specific test file
uv run pytest tests/unit/controllers/test_graph_controller.py -v
# Run only unit tests
uv run pytest tests/unit/ -v# Install linter
uv sync --extra dev
# Linting
uv run ruff check app/
# Formatting
uv run ruff format app/Pull requests are welcome! To contribute follow this guidelines.