def accepts_auth_key(func):
 @wraps(func)
 def process(request, *args, **kwargs):
  request.authkey = None
  http_auth = request.META.get('HTTP_AUTHORIZATION', '')
  if http_auth:
   try:
    (basic, b64_auth) = http_auth.split(' ', 1)
    if ('Basic' == basic):
     auth = base64.decodestring(b64_auth)
     (key_id, secret) = auth.split(':', 1)
     key = Key.objects.get(key=key_id)
     if key.check_secret(secret):
      request.authkey = key
      request.user = key.user
   except (binascii.Error, ValueError, Key.DoesNotExist):
    pass
  return func(request, *args, **kwargs)
 return process

def accepts_auth_key ( func ) : @ wraps ( func ) def process ( request , * args , ** kwargs ) : request . authkey = None http_auth = request . META . get ( 'HTTP_AUTHORIZATION' , '' ) if http_auth : try : ( basic , b64_auth ) = http_auth . split ( ' ' , 1 ) if ( 'Basic' == basic ) : auth = base64 . decodestring ( b64_auth ) ( key_id , secret ) = auth . split ( ':' , 1 ) key = Key . objects . get ( key = key_id ) if key . check_secret ( secret ) : request . authkey = key request . user = key . user except ( binascii . Error , ValueError , Key . DoesNotExist ) : pass return func ( request , * args , ** kwargs ) return process
enable a view to accept an auth key via http basic auth .