Skip to content

Simple Django REST framework JSON Web Token (JWT) example application

License

Notifications You must be signed in to change notification settings

freemanpd/django-rest-framework-jwt-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-rest-framework-example

An example "Django REST framework" JSON Web Token "(JWT)" application.

Build Status

Requirements

  1. Python 3.6+
  2. Pipenv

Installation

  1. Start Python virtual ENV
pipenv shell
  1. Install dependencies
pipenv install
  1. Run database migrations
python manage.py migrate
  1. Create admin user
python manage.py createsuperuser --username admin

Run application

python manage.py runserver

Once the server is running, visit http://127.0.0.1:8000 in your web browser. Now, you should see something like the following:

Note: access the Django admin interface here: http://127.0.0.1:8000/admin. Example:

Django admin login

Endpoints

  • api/v1/
  • api/token/
  • api/token/refresh/
  • health_check/ health_check

API/endpoint examples

Obtain token

curl -XPOST http://localhost:8000/api/token/  -H "Content-Type: application/json" -d '{"username": "admin", "password": "password123"}' 

...
{"refresh":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTYwMDEwMjU4NywianRpIjoiMjE3NmE1MTNhMTIyNDM5MmEwMTk0NDlhY2ZjNzg0NGIiLCJ1c2VyX2lkIjoxfQ.RjXDUt90_W7t6N-h4P333clLbQ5oDLHSS3suQ56w1_Q","access":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjAwMTAyNTg3LCJqdGkiOiI4ZmY0YjVkMTNmMTY0MDk4YjVmMGE2MmUwMTRhMGUwZSIsInVzZXJfaWQiOjF9.pOof6NyWHSfFVcJrJhpQMlAEzFKpyR9aTj-og_OpVaE"}

Create content

rest

Retrieve content

curl -XGET http://localhost:8000/api/v1/ -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjAwMTAzMjI2LCJqdGkiOiIzZTJiMWNmMzI1YTc0YjNhOTA2OGEwYWI0Y2IxNWJkMCIsInVzZXJfaWQiOjF9.BPjzsKgIWrgRn-qwjqCklKQ52KEJOnVjPNULE58MbkM" 

Check appliction health

curl -XGET http://localhost:8000/health_check/?format=json

Resources

Releases

No releases published

Packages

No packages published