Core: add jwt auth
This commit is contained in:
parent
1e0ffd9b2d
commit
495312b060
12 changed files with 234 additions and 17 deletions
43
jwtauth/views.py
Normal file
43
jwtauth/views.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
from rest_framework.decorators import api_view
|
||||
from rest_framework_simplejwt.tokens import RefreshToken
|
||||
from rest_framework_simplejwt.exceptions import InvalidToken
|
||||
from rest_framework_simplejwt.tokens import UntypedToken
|
||||
import json
|
||||
|
||||
from .models import OkService
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
def register_service(request):
|
||||
try:
|
||||
data = dict(json.loads(request.body.decode('utf-8')))
|
||||
print(data, type(data))
|
||||
if "shared_key" in dict(data).keys:
|
||||
if first_step_check():
|
||||
...
|
||||
|
||||
services = OkService.objects.all()
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
|
||||
def first_step_check(shared_key):
|
||||
service_id = 1
|
||||
return service_id
|
||||
|
||||
|
||||
def generate_tokens(service_id):
|
||||
refresh = RefreshToken.for_user(service_id)
|
||||
return {
|
||||
'refresh': str(refresh),
|
||||
'access': str(refresh.access_token),
|
||||
}
|
||||
|
||||
|
||||
def validate_token(token):
|
||||
try:
|
||||
UntypedToken(token)
|
||||
return True
|
||||
except InvalidToken:
|
||||
return False
|
Loading…
Add table
Add a link
Reference in a new issue