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
@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
@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
Release history Release notifications | RSS feed
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.1.tar.gz
(17.0 kB
view hashes)
Built Distributions
jwt_django-1.1-py3.10.egg
(19.1 kB
view hashes)
jwt_django-1.1-py3-none-any.whl
(16.4 kB
view hashes)