Skip to content

manikanta1213/token_based_authentication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TOKEN BASED AUTHENTICATION

Technology stack: Python, django Knowledge required: Postman, curl, python, django, REST API's

This project's purpose is to demonstrate token based authentication using django rest framework.

Steps to run this project:

open the terminal and run the following commands

  1. pip install -r requirements.txt

  2. python manage.py runserver or py -3 manage.py runserver

  3. create admin user using command py -3 manage.py createsuperuser --username 'your username' --email 'your email'

  4. login to django admin panel http:127.0.0.1:8000/admin

  5. once the user is created. execute the curl command to get the token curl --location --request POST 'http://127.0.0.1:8000/get/token'
    --header 'Content-Type: application/json'
    --data-raw '{ "username": "", "password": "" }'

  6. Use the token to create data using POST API curl --location --request POST 'http://127.0.0.1:8000/api/message/'
    --header 'Authorization: Token '
    --header 'Content-Type: application/json'
    --data-raw '{"body":"Hi, Checking the post method"}'

    It posts the data and the data gets stored in the database. It only allows 10 messages per hour for a user. Output: { "id": 22, "message": "Hi, Checking the post method", "created_at": "2022-05-16T17:39:15.387416Z", "updated_at": "2022-05-16T17:39:15.387416Z", "created_by": { "id": 1, "username": "manikanta", "email": "manikanta@mydashllc.com" } }

  7. Update the message using the curl call curl --location --request POST 'http://127.0.0.1:8000/api/delete/message/<message_id>/'
    --header 'Authorization: Token '
    --header 'Content-Type: application/json'
    --data-raw '{"body":"message of the body"}'

  8. Delete the message using the curl call. curl --location --request DELETE 'http://127.0.0.1:8000/api/delete/message/<message_id>/'
    --header 'Authorization: Token '

  9. To get information about the message curl --location --request GET 'http://127.0.0.1:8000/api/get/message/<message_id>/'
    --header 'Authorization: Token '

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages