All Projects → tOkeshu → activitypub-example

tOkeshu / activitypub-example

Licence: AGPL-3.0 license
An ActivityPub server implementation example

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to activitypub-example

Andstatus
Multiple accounts client for multiple Social networks. For Android
Stars: ✭ 236 (+171.26%)
Mutual labels:  activitypub
pylodon
Flask-based ActivityPub server
Stars: ✭ 86 (-1.15%)
Mutual labels:  activitypub
mastodon
Your self-hosted, globally interconnected microblogging community
Stars: ✭ 29,949 (+34324.14%)
Mutual labels:  activitypub
cherrypick
🌎 A interplanetary communication platform 🚀
Stars: ✭ 40 (-54.02%)
Mutual labels:  activitypub
bookwyrm
Social reading and reviewing, decentralized with ActivityPub
Stars: ✭ 1,499 (+1622.99%)
Mutual labels:  activitypub
mastodo
A fork of the GNU Social/AP-compatible microblogging server
Stars: ✭ 29 (-66.67%)
Mutual labels:  activitypub
Writefreely
A clean, Markdown-based publishing platform made for writers. Write together, and build a community.
Stars: ✭ 2,479 (+2749.43%)
Mutual labels:  activitypub
serverless-activitypub
An implementation of an ActivityPub Server.
Stars: ✭ 33 (-62.07%)
Mutual labels:  activitypub
ligh7hau5
A Matrix (https://matrix.org/docs/spec/) to Fediverse / ActivityPub client / bridge. Also, some media proxying.
Stars: ✭ 26 (-70.11%)
Mutual labels:  activitypub
tranquility
Small ActivityPub server (WIP)
Stars: ✭ 30 (-65.52%)
Mutual labels:  activitypub
soundstorm
The Federated Social Audio Platform
Stars: ✭ 26 (-70.11%)
Mutual labels:  activitypub
fedbox
Reference implementation of an ActivityPub service using go-ap packages
Stars: ✭ 76 (-12.64%)
Mutual labels:  activitypub
orb
A DID method implementation that extends the Sidetree protocol into a Fediverse of interconnected nodes and witnessed using certificate transparency. Spec: https://trustbloc.github.io/did-method-orb/
Stars: ✭ 25 (-71.26%)
Mutual labels:  activitypub
guide
WIP - ActivityPub Guide
Stars: ✭ 25 (-71.26%)
Mutual labels:  activitypub
misskey
🌎 An interplanetary microblogging platform 🚀
Stars: ✭ 2,895 (+3227.59%)
Mutual labels:  activitypub
Anfora
🏺 Self-hosted photo gallery social network. Under development
Stars: ✭ 197 (+126.44%)
Mutual labels:  activitypub
Big-List-of-ActivityPub
Big List of ActivityPub Projects
Stars: ✭ 93 (+6.9%)
Mutual labels:  activitypub
gancio
a shared agenda for local communities (with activitypub support)
Stars: ✭ 21 (-75.86%)
Mutual labels:  activitypub
beep-beep
Fictional p2p protocol
Stars: ✭ 34 (-60.92%)
Mutual labels:  activitypub
writefreely
A clean, Markdown-based publishing platform made for writers. Write together and build a community.
Stars: ✭ 2,866 (+3194.25%)
Mutual labels:  activitypub

ActivityPub example server

This is an example server implementing a few basic features of activitypub.

Because ActivityPub is quite generic, the goal here is not to implement every aspect of ActivityPub but just a coherent subset that can be used for understanding the protocol as well as for testing. Thus the use case is microblogging: users can only publish or like notes and follow each others.

Features

Outbox:

  • Accept Create activities
  • Accept Follow activities
  • Accept Like activities
  • Accept non-activity objects and convert them to a Create activity (only accepts Note objects for now since it is an example server)

Delivery:

  • Handle to audience
  • Handle cc audience
  • Handle bto and bcc
  • Handle audience audience

Inbox:

  • Accept Create activities
  • Accept Follow activities
  • Accept Like activities

Getting started

Install requirements (probably in a virtualenv):

$ pip install django requests

Clone this repository:

$ git clone https://github.com/tOkeshu/activitypub-example.git

Run the migrations

$ cd activitypub
$ ./manage.py migrate

Run the server

$ ./manage.py runserver

Testing the federation

Testing the federation is a tat trickier. You can use a reverse proxy to simulate remote servers.

First add two new hosts in your hosts file:

$ cat /etc/hosts
...
127.0.1.1	alice.local bob.local
...

Then add two new virtual hosts for alice.local and bob.local. Here is an example nginx configuration file to achieve that:

server {
    listen 80;
    index index.html index.htm;

    server_name alice.local;
    server_name_in_redirect off;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header X-Forwarded-Host $host;
    }
}

Copy the file and change alice.local to bob.local and the port to 8001. You'll also need two different Django configuration files. So copy activitypub/settings.py to activitypub/settings-bob.py and change the following values:

$ cat activitypub/settings-bob.py
...
ACTIVITYPUB_DOMAIN = "alice.local" # or bob.local
...
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'alice.sqlite3'), # or bob.sqlite3
    }
}

Now you can run the migrations for alice (default) and bob:

$ ./manage.py migrate --settings=activitypub.settings
$ ./manage.py migrate --settings=activitypub.settings-bob

Finally run the two servers in different terminals:

$ ./manage.py runserver # alice
$ ./manage.py runserver 8001 --setttings=activitypub.settings-bob

Check that the servers are reachable via the correct hosts:

If all works correctly they should be able to reach each others. To verify that, we need to first create users. The simplest way is to do it via the python shell:

$ ./manage.py shell
...
>>> from activitypub.models import Person
>>> alice = Person(username="alice", name="Alice in Wonderland")
>>> alice.save()

Alice's actor representation should be available at http://alice.local/@alice. Now do that same for Bob:

$ ./manage.py shell --settings=activitypub.settings-bob
...
>>> from activitypub.models import Person
>>> bob = Person(username="bob", name="Robert Paulson")
>>> bob.save()

Again, Bob's representation should be available at http://bob.local/@bob. Let's make Alice follow bob:

$ curl -X POST 'http://alice.local/@alice/outbox' -H "Content-Type: application/activity+json" -d '{"type": "Follow", "object": "http://bob.local/@bob"}'

If everything went fine, we should be able to find Bob in Alice's following collection and Alice in Bob's followers collection:

If Bob publishes a note as follow:

$ curl -X POST 'http://bob.local/@bob/outbox' -H "Content-Type: application/activity+json" -d '{"type": "Note", "content": "Good morning!"}'

We should be able to find the new note on Alice's instance: http://alice.local/@[email protected]/notes

API

Create a new note:

POST /@alice/outbox HTTP/1.1
Host: social.example.com
Content-Type: application/activity+json

{
  "type": "Create",
  "to": "https://social.example.com/@alice/followers",
  "object": {
    "type": "Note",
    "content": "Hello world!"
  }
}

Create a new note without an activity:

POST /@alice/outbox HTTP/1.1
Host: social.example.com
Content-Type: application/activity+json

{
  "type": "Note",
  "content": "Hello world!"
}

Follow someone:

POST /@alice/outbox HTTP/1.1
Host: social.example.com
Content-Type: application/activity+json

{
  "type": "Follow",
  "object": "https://social.example.com/@bob"
}

License

This ActivityPub example server is released under the terms of the GNU Affero General Public License v3 or later.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].