123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- # -*- coding: utf-8 -*-
- from __future__ import unicode_literals
- from tastypie.authentication import Authentication
- from django.contrib.auth.models import User
- from .jwt_token import check_token, get_username
- import simplejson as json
- class JWTAuthentication(Authentication):
- '''
- '''
- def is_authenticated(self, request, **kwargs):
- # Check content type
- if request.content_type != 'application/json':
- return False
- # Check body
- if not request.body:
- return False
- body = json.loads(request.body)
- # Check required parameters
- if 'token' not in body:
- return False
- return check_token(body['token'])
- '''
- '''
- def get_identifier(self, request):
- # Check content type
- if request.content_type != 'application/json':
- return None
- # Check body
- if not request.body:
- return None
- body = json.loads(request.body)
- # Check required parameters
- if 'token' not in body:
- return None
- return get_username(body['token'])
|