Skip to content

Simple RestAPI POC using flask-restplus (JWT & python decorators)

Notifications You must be signed in to change notification settings

binc75/restplusApi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RestPLUS Flask RestAPI POC

Simple RestAPI POC using flask-restplus with authentication capabilities, JWT (JSON Web Token) management and python decorators.

Out of the box this library provide a Swagger interface!

Alt text

Usage

Launch the restplusApiJWT.py and visit http://127.0.0.1:8080

Installation

with virtualenv

Install python3-virtualenv on your machine, then

git clone [email protected]:binc75/restplusApi.git
cd restplusApi/
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt --no-cache
./restplusApiJWT.py

Quick example

Get the token after succesful authentication

TOKEN=$(curl --user admin:12345 http://127.0.0.1:8080/login | jq -r '.token')

Post data using the token

curl -s -X POST -d '{"domain": "example.com", "hostname": "host01", "ip": "192.168.1.2"}' -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" http://127.0.0.1:8080/addrecord | jq .

Passwords hash generation

In order to creae the hased passwords to put in the JSON file follow this procedure.

>>> import bcrypt
>>> password = 'abc123'
>>> hashed = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt())
>>> print(hashed.decode('UTF-8'))
$2b$12$6jqow5hAKmvl5AHCIOtjkuVavhyFFV7.Dnyc6gFdFWH0BG3IT1SEO

About

Simple RestAPI POC using flask-restplus (JWT & python decorators)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages