code: def key_required(group=None, perm=None, keytype=None):
      
      def decorator(f):
          def wrapper(request, *args, **kwargs):
              try:
                  validate_key( request, group, perm, keytype )
                  return f(request, *args, **kwargs)
              except AccessUnauthorized:
                  return HttpResponse401( request )
              except AccessForbidden:
                  return HttpResponse403( request )
          return wrapper 
      return decorator
docs: Decorator for key authentication