Skip to main content

Provide end-to-end control jwt token (Simple & Easy to Use)

Project description

jwt_django

jwt_django is very useful package for django developers to create, read, authenticate jwt token.
jwt_django provide end-to-end control jwt token

How to install jwt_django

pip install jwt_django

How to use jwt_django

Configuration

# setting.py
 INSTALLED_APPS = [
            ....
       'jwt_django',
       
        ]
# views.py

from jwt_django.core import GenerateKey,JWTToken
from django.contrib.auth import authenticate




secret_key = GenerateKey.generate_key() # Create Every time new secret key, dont use production, in production use static key
user = JWTToken(secret_key=secret_key,expiry_token=5)



@api_view(['POST'])
def login(request):
    if request.method == 'POST':
        username = request.data["username"]
        password = request.data["password"]
        user_auth = authenticate(username=username, password=password)
     
        if user_auth is not None:
            token = user.createToken({
            "user_id":user_auth.id,
            "username":username
             })
            return Response({"token":token})
        return Response({"invalid-credentials":"Wrong username and password"})

Pass Authorization Token

Screenshot (78)

@api_view(['POST'])
def data_view(request):
    # Set header
    # Authorization:mytoken
    print(user.authuser(request,"user_id","username"))
    
   
    return Response({
       "username":user.authuser(request,"user_id","username")
    })

Authenticated

print(user.isAuthenticated(request)) # Return Bool
print(user.is_authenticated()) # Return Bool

Pass Cache-Control Token

Screenshot (80)

@api_view(['POST'])
def data_view(request):
    # Set header
    # Cache-Control:mytoken
    print(user.tokenInfo(request,"myinfo1","myinfo2"))
    
   
    return Response({
       "username":user.tokenInfo(request,"myinfo1","myinfo2")
    })

Check Our Site : https://mefiz.com
Github : https://github.com/MominIqbal-1234/jwt_django Developed by : Momin Iqbal

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jwt_django-1.0.tar.gz (16.9 kB view hashes)

Uploaded Source

Built Distribution

jwt_django-1.0-py3-none-any.whl (16.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page