Authentication microservice, the goal of this project is to learn Python and FastApi, it will be updated as new versions of these tools are released.
It is a microservice for user administration and authenication, using JWT tokens and encrypting the information within it, different approaches are used, that is why there may be different implementations performing the same functions.
- Python 3.12+
- FastApi 0.124+
Important
It is necessary to complete the configuration file(.env), and create the PEM files and place them in the root folder
- Create a virtual environment
python -m venv .venv- Activate it (Linux, macOS)
source .venv/bin/activateActivate it (Windows PowerShell)
.venv\Scripts\Activate.ps1- Install dependencies
pip install -r requirements.txt- Generate the RSA keys files and name them as 'private_key.pem' and 'public_key.pem', and place them in the project's root folder
openssl genrsa -out private_key.pem 2048chmod 0400 private.pemUse the private key file to extract the public key in PEM format
openssl rsa -in private_key.pem -pubout -out public_key.pem- Set configuration file (.env)
The microservice uses mongoDB as its database, so the connection string and other configurations (mongodb, JWT, CORS, logs) must be included
- Run local development server
uvicorn src.main:app --reload- Open the next url in a browser to see the Swagger UI
http://127.0.0.1:8000/docs- Create the image
docker build -t auth-service:latest .Or download the image hosted in this repository.
docker pull ghcr.io/ablogo/authfastapi:latest- Run a container from the image previously created
docker run -p 8000:80 --env-file .env auth-service:latestNote
Since the project is used for learning, it does not strictly follow the concept of microservices, where each microservice should have its own realm of responsability