@rmdes/indiekit-endpoint-activitypub 2.0.24 → 2.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -60,6 +60,7 @@ import {
60
60
  } from "./lib/controllers/featured-tags.js";
61
61
  import { resolveController } from "./lib/controllers/resolve.js";
62
62
  import { publicProfileController } from "./lib/controllers/public-profile.js";
63
+ import { authorizeInteractionController } from "./lib/controllers/authorize-interaction.js";
63
64
  import { myProfileController } from "./lib/controllers/my-profile.js";
64
65
  import { noteObjectController } from "./lib/controllers/note-object.js";
65
66
  import {
@@ -173,6 +174,10 @@ export default class ActivityPubEndpoint {
173
174
  // dereference the Note ID during Create activity verification.
174
175
  router.get("/quick-replies/:id", noteObjectController(self));
175
176
 
177
+ // Authorize interaction — remote follow / subscribe endpoint.
178
+ // Remote servers redirect users here via the WebFinger subscribe template.
179
+ router.get("/authorize_interaction", authorizeInteractionController(self));
180
+
176
181
  // HTML fallback for actor URL — serve a public profile page.
177
182
  // Fedify only serves JSON-LD; browsers get 406 and fall through here.
178
183
  router.get("/users/:identifier", publicProfileController(self));
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Authorize Interaction controller — handles the remote follow / authorize
3
+ * interaction flow for ActivityPub federation.
4
+ *
5
+ * When a remote server (WordPress AP, Misskey, etc.) discovers our WebFinger
6
+ * subscribe template, it redirects the user here with ?uri={actorOrPostUrl}.
7
+ *
8
+ * Flow:
9
+ * 1. Missing uri → render error page
10
+ * 2. Unauthenticated → redirect to login, then back here
11
+ * 3. Authenticated → redirect to the reader's remote profile page
12
+ */
13
+
14
+ export function authorizeInteractionController(plugin) {
15
+ return async (req, res) => {
16
+ const uri = req.query.uri || req.query.acct;
17
+ if (!uri) {
18
+ return res.status(400).render("activitypub-authorize-interaction", {
19
+ title: "Authorize Interaction",
20
+ mountPath: plugin.options.mountPath,
21
+ error: "Missing uri parameter",
22
+ });
23
+ }
24
+
25
+ // Clean up acct: prefix if present
26
+ const resource = uri.replace(/^acct:/, "");
27
+
28
+ // Check authentication — if not logged in, redirect to login
29
+ // then back to this page after auth
30
+ const session = req.session;
31
+ if (!session?.access_token) {
32
+ const returnUrl = `${plugin.options.mountPath}/authorize_interaction?uri=${encodeURIComponent(uri)}`;
33
+ return res.redirect(
34
+ `/session/login?redirect=${encodeURIComponent(returnUrl)}`,
35
+ );
36
+ }
37
+
38
+ // Authenticated — redirect to the remote profile viewer in our reader
39
+ // which already has follow/unfollow/like/boost functionality
40
+ const encodedUrl = encodeURIComponent(resource);
41
+ return res.redirect(
42
+ `${plugin.options.mountPath}/admin/reader/profile?url=${encodedUrl}`,
43
+ );
44
+ };
45
+ }
@@ -262,6 +262,18 @@ export function setupFederation(options) {
262
262
  // instance actor's keys for outgoing fetches), which Fedify doesn't yet
263
263
  // support out of the box. Re-enable once Fedify adds this capability.
264
264
 
265
+ // --- WebFinger custom links ---
266
+ // Add OStatus subscribe template so remote servers (WordPress AP, Misskey, etc.)
267
+ // can redirect users to our authorize_interaction page for remote follow.
268
+ federation.setWebFingerLinksDispatcher((_ctx, _resource) => {
269
+ return [
270
+ {
271
+ rel: "http://ostatus.org/schema/1.0/subscribe",
272
+ template: `${publicationUrl}${mountPath.replace(/^\//, "")}/authorize_interaction?uri={uri}`,
273
+ },
274
+ ];
275
+ });
276
+
265
277
  // --- Inbox listeners ---
266
278
  const inboxChain = federation.setInboxListeners(
267
279
  `${mountPath}/users/{identifier}/inbox`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rmdes/indiekit-endpoint-activitypub",
3
- "version": "2.0.24",
3
+ "version": "2.0.25",
4
4
  "description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.",
5
5
  "keywords": [
6
6
  "indiekit",
@@ -0,0 +1,10 @@
1
+ {% extends "document.njk" %}
2
+
3
+ {% from "prose/macro.njk" import prose with context %}
4
+
5
+ {% block content %}
6
+ {% if error %}
7
+ {{ prose({ text: error }) }}
8
+ {% endif %}
9
+ <p><a href="{{ mountPath }}/">Return to dashboard</a></p>
10
+ {% endblock %}