mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Simplify the API authenticator
This commit is contained in:
@@ -4,23 +4,17 @@ from api.models import AuthAPIKey
|
|||||||
|
|
||||||
|
|
||||||
class APIKeyAuthentication(object):
|
class APIKeyAuthentication(object):
|
||||||
|
""" Validats a request by API key passed as a GET parameter """
|
||||||
|
|
||||||
def is_authenticated(self, request):
|
def is_authenticated(self, request):
|
||||||
|
try:
|
||||||
params = {}
|
keyobj = AuthAPIKey.objects.get(key=request.GET.get('apikey', None))
|
||||||
for key, value in request.GET.items():
|
except AuthAPIKey.DoesNotExist:
|
||||||
params[key.lower()] = value
|
pass
|
||||||
|
else:
|
||||||
if 'apikey' in params:
|
|
||||||
try:
|
|
||||||
keyobj = AuthAPIKey.objects.get(key=params['apikey'])
|
|
||||||
except:
|
|
||||||
keyobj = None
|
|
||||||
|
|
||||||
if keyobj and keyobj.active:
|
if keyobj and keyobj.active:
|
||||||
request.user = AnonymousUser()
|
request.user = AnonymousUser()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def challenge(self):
|
def challenge(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user