Skip to content

This is an example as how a system with 3 services and JWT (JSON Web Tokens) works.

License

Notifications You must be signed in to change notification settings

evangelos-dimitriadis/Auth-Resource-Client-JWT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple Auth-Resource-Client JWT example in Flask

This is an example as how a system with 3 services and JWT (JSON Web Tokens) works. Instead of heaving the authentication at the same service as the resources are, we devide those into two dedicated services. Public-key cryptography is being used where the authorization has access to the user database and can generate tokens using the private key (jwt-key), while the resource server can use those to grant access to the API using the public key (jwt-key.pub). This way only one service has access to the database which includes the hashed passwords and potential many more information, while other services can verify the tokens without having to make a call to the authentication server.

SECURITY NOTICE

The existing private and public keys exist ONLY as an example. You could create your own key set by typing (and naming them jwt_token):

ssh-keygen -t rsa -b 4096 -m pem

Requirements

python3.11 libpython3.11-dev (Ubuntu) or similar for other OS for installation of uWSGI and a C compiler (gcc and clang are supported)

You can also use the docker-compose.

How to run the project

Using virtual enviroment for the servers

  1. From the auth folder enter the virtual enviroment, install the libraries and start the server:

python3.11 -m venv env source env/bin/activate pip install -r requirements.txt uwsgi --ini uwsgi.ini --honour-std

  1. From the resources-server folder enter the virtual enviroment, install the libraries and start the server:

python3.11 -m venv env source env/bin/activate pip install -r requirements.txt uwsgi --ini uwsgi.ini --honour-std

Using the containers for the servers

Build and start the containers:

docker-compose build docker-compose up

Run the client

  1. From the client folder enter the virtual enviroment, install the libraries and start the server:

python3.11 -m venv env source env/bin/activate pip install -r requirements.txt python client.py

Testing

Both servers can be tested by typing from each folder:

python -m pytest tests

About

This is an example as how a system with 3 services and JWT (JSON Web Tokens) works.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published