Skip to content

Basic JWT Authentication between different services

Notifications You must be signed in to change notification settings

mebaysan/Auth-101

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

Nowadays, I am eager to learn microservices architecture and technologies. I was super wondering that how to handle authentication between different systems? In this repo, I experienced that in the easiest way.

Also, you can check my text I published on Medium that I wrote to explain this code.

Worst Diagram

Containers & Images

Auth Service

auth101-auth

docker pull mebaysan/auth101-auth

docker container run -d -p 5000:5000 mebaysan/auth101-auth

Gateway Service

auth101-gateway

docker pull mebaysan/auth101-gateway

docker container run -d -p 8080:8080 mebaysan/auth101-gateway

Nomad Applied Example

After installing Nomad and creating a local dev agent, you can execute nomad_start.sh script.

sudo apt-get install python3-httpx

# 172.17.0.3 => IP address given by Nomad to the task(s), you can check is it the same on your local or not.

# To be authenticated
httpx -m POST --auth user@user.com Passw0rd http://172.17.0.3:8080/login

# Get all posts in the db (you have to be authenticated)
httpx -m GET -h "Authorization" "Bearer <TOKEN>" http://172.17.0.3:8080/posts

# Add a new post to the db (you have to be authenticated)
httpx -m POST -h "Authorization" "Bearer <TOKEN>" -j '{"id":1, "title": "Title Text"}' http://172.17.0.3:8080/posts

About

Basic JWT Authentication between different services

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published