Auth via API key, also added Admin interface to edit keys

This commit is contained in:
2010-06-15 21:05:53 +01:00
parent 7d90ddaec0
commit 78ca607608
4 changed files with 58 additions and 4 deletions

24
api/auth.py Normal file
View File

@@ -0,0 +1,24 @@
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):
apikey = request.GET.get('apikey', None)
if apikey:
try:
keyobj = AuthAPIKey.objects.get(key=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')