Giter Site home page Giter Site logo

django-jwt's Introduction

django-jwt

A Django simple Application with Authentication

In this repo the_site is project, having two apps 'auth' and 'home'

Steps how JWT based authentication is implemented

  1. pip install djangorestframework_simplejwt

  2. Settings.py

INSTALLED_APPS = [
    'rest_framework',
]

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ],
}
  1. urls.py
In the_site.auth.urls
    path('hello/', views.HelloView.as_view(), name='hello'),
In the_site.urls
    path('api/token/', jwt_views.TokenObtainPairView.as_view(), name='token_obtain_pair'),
    path('api/token/refresh/', jwt_views.TokenRefreshView.as_view(), name='token_refresh'),
  1. In auth.views.py
from django.views import View

class HelloView(APIView):
    permission_classes = (IsAuthenticated,)

    def get(self, request):
        content = {'message': 'Hello, World!'}
        return Response(content)
  1. Do below steps:
  2. python manage.py migrate
  3. python manage.py createsuperuser
  4. pip3 install httpie
  5. Generate Tokens by visiting webpage: http://127.0.0.1:8000/api/token/ OR from cli do curl -u username http://127.0.0.1:8000/api/token/
  6. http http://127.0.0.1:8000/auth/hello/ "Authorization: Bearer "

Screenshot 2021-07-22 at 19 03 22

  1. After 5 minutes, access token will expire. We can get new access token using refresh token http post http://127.0.0.1:8000/api/token/refresh/ refresh=

Screenshot 2021-07-22 at 19 05 02

django-jwt's People

Contributors

er-sumit avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.