diff --git a/mastodon/input.py b/mastodon/input.py index 9ada172..3c2502e 100644 --- a/mastodon/input.py +++ b/mastodon/input.py @@ -33,6 +33,7 @@ class MastodonInputOptions: default_factory=lambda: ALLOWED_VISIBILITY.copy() ) filters: list[re.Pattern[str]] = field(default_factory=lambda: []) + url_query_auth: bool = False @classmethod def from_dict(cls, data: dict[str, Any]) -> "MastodonInputOptions": @@ -56,6 +57,11 @@ class MastodonInputService(MastodonService, InputService): super().__init__(options.instance, db, http) self.options: MastodonInputOptions = options + if options.url_query_auth: + self.log.warning( + "Using URL query auth! This is less secure than the default!" + ) + self.log.info("Verifying '%s' credentails...", self.url) response = self.verify_credentials() self.user_id: str = response["id"] @@ -249,7 +255,12 @@ class MastodonInputService(MastodonService, InputService): @override async def listen(self): url = f"{self.streaming_url}/api/v1/streaming?stream=user" - headers = {"Authorization": f"Bearer {self.options.token}"} + headers = {} + + if not self.options.url_query_auth: + headers["Authorization"] = f"Bearer {self.options.token}" + else: + url += f"&access_token={self.options.token}" async for msg in listen_websocket(url, self.log, headers=headers): self.submitter(lambda: self._accept_msg(msg))