Initial commit

This commit is contained in:
jar3b 2018-07-06 18:47:11 +03:00
commit 94fc866891
8 changed files with 60 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.idea/
venv/

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# drf-uuid-auth
Плагин для DRF для аутентификации посредством tantald

View File

@ -0,0 +1,8 @@
__title__ = 'drf-uuid-auth'
__version__ = '0.0.1'
__author__ = 'jar3b'
__license__ = 'MIT'
__copyright__ = 'Copyright 2017-2018 Jar3b'
# Version synonym
VERSION = __version__

View File

@ -0,0 +1,33 @@
from django.contrib.auth import get_user_model
from rest_framework import exceptions
from rest_framework.authentication import BaseAuthentication
from drf_uuid_auth.settings import api_settings
class UuidAuthentication(BaseAuthentication):
def authenticate(self, request):
header = request.META.get(api_settings.AUTH_HEADER.upper(), None)
if header is None or header == "" or header == "-":
return None
payload = header
user = self.authenticate_credentials(payload)
return user, payload
def authenticate_credentials(self, payload):
User = get_user_model()
try:
user = User.object.get(uuid=payload)
except User.DoesNotExist:
raise exceptions.AuthenticationFailed("Invalid user id")
if not user.is_active:
raise exceptions.AuthenticationFailed("User isn't active")
return user
def authenticate_header(self, request):
pass

0
drf_uuid_auth/models.py Normal file
View File

13
drf_uuid_auth/settings.py Normal file
View File

@ -0,0 +1,13 @@
import datetime
from django.conf import settings
from rest_framework.settings import APISettings
USER_SETTINGS = getattr(settings, 'UUID_AUTH', None)
DEFAULTS = {
'AUTH_HEADER': 'HTTP_X_UUID_AUTH'
}
api_settings = APISettings(USER_SETTINGS, DEFAULTS)

0
drf_uuid_auth/utils.py Normal file
View File

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
djangorestframework>=3.4.0