Initial commit
This commit is contained in:
commit
94fc866891
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
.idea/
|
||||||
|
venv/
|
3
README.md
Normal file
3
README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# drf-uuid-auth
|
||||||
|
|
||||||
|
Плагин для DRF для аутентификации посредством tantald
|
8
drf_uuid_auth/__init__.py
Normal file
8
drf_uuid_auth/__init__.py
Normal 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__
|
33
drf_uuid_auth/authentication.py
Normal file
33
drf_uuid_auth/authentication.py
Normal 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
0
drf_uuid_auth/models.py
Normal file
13
drf_uuid_auth/settings.py
Normal file
13
drf_uuid_auth/settings.py
Normal 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
0
drf_uuid_auth/utils.py
Normal file
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
djangorestframework>=3.4.0
|
Loading…
x
Reference in New Issue
Block a user