mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Reorganise the file structure into a project tree
This commit is contained in:
27
app/api/auth.py
Normal file
27
app/api/auth.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from django.http import HttpResponseForbidden
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from api.models import AuthAPIKey
|
||||
|
||||
|
||||
class APIKeyAuthentication(object):
|
||||
|
||||
def is_authenticated(self, request):
|
||||
|
||||
params = {}
|
||||
for key, value in request.GET.items():
|
||||
params[key.lower()] = value
|
||||
|
||||
if 'apikey' in params:
|
||||
try:
|
||||
keyobj = AuthAPIKey.objects.get(key=params['apikey'])
|
||||
except:
|
||||
keyobj = None
|
||||
|
||||
if keyobj and keyobj.active:
|
||||
request.user = AnonymousUser()
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def challenge(self):
|
||||
return HttpResponseForbidden('Access Denied, use a API Key')
|
||||
Reference in New Issue
Block a user