From 9768e673d76501d3ff5806d56ceda43ceea62ab0 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 11 Aug 2019 14:25:43 +0200 Subject: [PATCH] Enable authenticated fetches --- blueprints/tasks.py | 4 +--- core/activitypub.py | 6 +++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/blueprints/tasks.py b/blueprints/tasks.py index 2d8ebfb..d98542b 100644 --- a/blueprints/tasks.py +++ b/blueprints/tasks.py @@ -10,13 +10,13 @@ from little_boxes import activitypub as ap from little_boxes.errors import ActivityGoneError from little_boxes.errors import ActivityNotFoundError from little_boxes.errors import NotAnActivityError -from little_boxes.httpsig import HTTPSigAuth from requests.exceptions import HTTPError import config from config import DB from config import MEDIA_CACHE from core import gc +from core.activitypub import SIG_AUTH from core.activitypub import Box from core.activitypub import _actor_hash from core.activitypub import _add_answers_to_question @@ -41,8 +41,6 @@ from core.tasks import Tasks from utils import now from utils import opengraph -SIG_AUTH = HTTPSigAuth(config.KEY) - blueprint = flask.Blueprint("tasks", __name__) diff --git a/core/activitypub.py b/core/activitypub.py index 4d1e728..fbaee28 100644 --- a/core/activitypub.py +++ b/core/activitypub.py @@ -23,11 +23,13 @@ from little_boxes.activitypub import clean_activity from little_boxes.activitypub import format_datetime from little_boxes.backend import Backend from little_boxes.errors import ActivityGoneError +from little_boxes.httpsig import HTTPSigAuth from config import BASE_URL from config import DB from config import EXTRA_INBOXES from config import ID +from config import KEY from config import ME from config import USER_AGENT from core.db import update_many_activities @@ -41,6 +43,7 @@ logger = logging.getLogger(__name__) _NewMeta = Dict[str, Any] +SIG_AUTH = HTTPSigAuth(KEY) _ACTIVITY_CACHE_ENABLED = True ACTORS_CACHE = LRUCache(maxsize=256) @@ -364,7 +367,8 @@ class MicroblogPubBackend(Backend): data = self._fetch_iri(iri) logger.debug(f"_fetch_iri({iri!r}) == {data!r}") else: - data = super().fetch_iri(iri) + # Pass the SIG_AUTH to enable "authenticated fetch" + data = super().fetch_iri(iri, auth=SIG_AUTH) logger.debug(f"fetch_iri({iri!r}) == {data!r}") return data