This repository contains a gRPC authentication server implemented in Python, using gRPC for communication and JWT for authentication.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Python 3.x
- pip
- virtualenv (optional, but recommended)
First, clone the repository to your local machine:
git clone https://github.com/seankwarren/grpc-jwt-auth-microservice.git
Then, navigate to the project directory:
cd grpc-jwt-auth-microservice
Optionally, create a virtual environment:
python -m venv .venv
Activate the virtual environment:
- On Linux/MacOS:
source .venv/bin/activate
- On Windows:
.venv\Scripts\activate
Install the required dependencies:
pip install -r requirements.txt
To start the gRPC authentication server, run:
python src/server.py
To run the tests, execute:
pytest src/**_test.py -v
Note: this will boot up a gRPC server on port 50051, so make sure the port is available.
Below are the environment variables used by the server:
ACCESS_TOKEN_LIFETIME
: Specifies the lifetime of access tokens in minutes. Default is 30 minutes.REFRESH_TOKEN_LIFETIME
: Specifies the lifetime of refresh tokens in days. Default is 30 days.JWT_SECRET
: Specifies the secret key used to sign JWT tokens.SERVER_PORT
: Specifies the port on which the gRPC server will listen. Default is 50051.
The project's folder structure is as follows:
.
├── build_protos.sh # Script to generate gRPC code from proto files
├── requirements.txt # Python dependencies
└── src # Source files
├── jwt_utils.py # JWT utility functions
├── protos # Proto files and generated gRPC code
│ ├── auth_service.proto
│ ├── auth_service_pb2.py
│ ├── auth_service_pb2.pyi
│ └── auth_service_pb2_grpc.py
├── server.py # gRPC server implementation
├── status.py # Status message definitions
└── test.py # Tests for the gRPC service
Sean Warren - Initial work
This project is licensed under the MIT License - see the LICENSE.md
file for details