Simplify the API authenticator

This commit is contained in:
2011-05-26 15:46:59 +01:00
parent 9dc81c74f2
commit cd4a0deaa8

View File

@@ -4,23 +4,17 @@ from api.models import AuthAPIKey
class APIKeyAuthentication(object):
""" Validats a request by API key passed as a GET parameter """
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
try:
keyobj = AuthAPIKey.objects.get(key=request.GET.get('apikey', None))
except AuthAPIKey.DoesNotExist:
pass
else:
if keyobj and keyobj.active:
request.user = AnonymousUser()
return True
return False
def challenge(self):