def auth_required(function):
    """
    Decorator to check the agent is authenticated.

    Unlike "login_required", if the agent is not authenticated it fails
    with a 401 error instead of redirecting.
    """
    def wrap(request, *args, **kwargs):
        # if request.user.is_authenticated():
        return function(request, *args, **kwargs)

        resp = HttpResponse()
        resp.status_code = 401
        return resp
    return wrap