# Federation support for Discourse

**URL:** https://meta.discourse.org/t/federation-support-for-discourse/90921
**Category:** Feature
**Tags:** completed
**Created:** [June 28, 2018, 5:32am UTC](https://meta.discourse.org/t/federation-support-for-discourse/90921 "2018-06-28T05:32:10Z")
**Posts on this page:** 1
**Showing post:** 87

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [February 13, 2023, 10:21am UTC](https://meta.discourse.org/t/federation-support-for-discourse/90921/87 "2023-02-13T10:21:12Z")

</div>

An update here. Pavilion and CDCK ([Discourse.org](http://Discourse.org)) are discussing building an ActivityPub plugin for Discourse. After some discussion, we’ve landed on the spec below. Any comments or suggestions welcome before we finalise it. Note that

- Support for incoming content (e.g. posts on Mastodon etc being imported into Discourse) is intentionally excluded. It will be possible to add this in a later version.

- Support for following users (as opposed to categories) is also intentionally excluded. It would also be possible to add this in a later version.

- Substantial parts of the specification are following the [approach taken by Lemmy](https://join-lemmy.org/docs/en/federation/overview.html).

- Pavilion will be building the MVP plugin (I’ll be working on it), and CDCK will own and host it (i.e. it will be a CDCK plugin, not a Pavilion plugin).

## Overview

An ActivityPub (AP) Plugin for Discourse.

The goal of the plugin is an MVP implementation of the [ActivityPub](https://www.w3.org/TR/activitypub), [ActivityVocab](https://www.w3.org/TR/activitystreams-vocabulary) and [ActivityStreams](https://www.w3.org/TR/activitystreams-core) specs in Discourse with one demonstrated integration of the MVP functionality for an AP compliant platform, namely [Mastodon](https://github.com/mastodon/mastodon). As far as possible, the implementation will be built to support further support of the protocols, and any extensions.

This specification concerns enabling AP support on a per-category basis where only the first post in each topic in an AP-enabled category is federated (“first post only”).

## Users

The plugin usage will be documented comprehensively on meta in a plugin topic.

### Normal User

1. Subscribes to (aka “follows”) a federation-enabled Discourse category (FDC) on Mastodon (or any other fediverse service) using the category’s handle, e.g. `@announcements@meta.discourse.org`.

2. Sees an excerpt of the first post of all FDC topics (posted after they subscribe) in their Mastodon feed, each with a link back to the associated topic, e.g. “Discuss on our forum”.

3. Any action related to the post in Mastodon does not appear in Discourse.

4. Any action related to the post in Discourse does not appear in Mastodon.

5. Federated posts excerpts can be controlled by the post author using markup similar to that used to control topic excerpts, e.g. `<div class="note">{text}</div>`

### Admin

1. Enables federation on a per-category basis using a category setting. Federation can only be enabled in categories visible to “everyone” on public instances.

2. Sets the category’s federated username via the category settings UI (cannot be changed).

3. Sets allow and deny lists of domains via site settings from which activity is automatically accepted or rejected.

4. Sets a “block list” of federated usernames to be part of a [Block object(s)](https://www.w3.org/TR/activitypub/#block-activity-outbox) in the server outbox.

5. Sets the maximum character length of a federated note using a site setting i.e. `activitypub_note_excerpt_maxlength`.

6. Sets the text associated with the link included in the first post of a federated Discourse topic in “Customize \> Text”.

7. Sets whether the link back (and text) to the forum is included in federated posts on a per-category basis.

8. Adds a key pair via site settings to sign federated content with.

## Technical

1. The plugin will include comprehensive testing (unit / integration and js tests).

2. The category is an automated ActivityPub [Actor](https://www.w3.org/TR/activitypub/#actor-objects) within Discourse (as a [Group](https://www.w3.org/ns/activitystreams#Group) ActorType). The federated preferredUsername is set at by the admin when enabling federation and stored in a category custom field. The federated name (aka display name) is the full\_name of the category.

3. Users are Actors in the content federated by the category Actor. The federated `preferredUsername` is the user’s Discourse username at the time of federation. A user’s `preferredUsername` is stored in a user custom field in case the user changes their Discourse username. The federated name (aka display name) is the user’s Discourse name.

4. In general, ActivityPub objects will be associated with their equivalent Discourse objects using custom fields where appropriate (e.g. object or actor ids), and new tables where appropriate (e.g. inbox and outbox).

5. The primary ActivityPub Activity to implement is [Follow](https://www.w3.org/TR/activitypub/#follow-activity-inbox) and associated activities and models required to implement it, i.e. inbox, outbox and required associated Actions and Collections.

6. Discourse posts would be federated as ActivityStream [Notes](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-note), with the content as HTML.

7. Authentication will be handled using HTTP Signatures, see [here](https://www.w3.org/wiki/SocialCG/ActivityPub/Authentication_Authorization) and [here](https://blog.joinmastodon.org/2018/06/how-to-implement-a-basic-activitypub-server/). All other [Security Considerations](https://www.w3.org/TR/activitypub/#security-considerations) in the ActivityPub spec will be addressed as appropriate.

8. Federation endpoints will be protected as appropriate for the specification, i.e. ensure redirect\_to\_login\_if\_required is used in controllers, add guardian for category everyone can see permission.

---

_[View the full topic](https://meta.discourse.org/t/federation-support-for-discourse/90921)._
