This project is not covered by Drupal’s security advisory policy.

This module will integrate with the Mastodon API, allowing you to "Toot" from within the Drupal interface.

The idea is that you can install this module if you want to quickly share your content with a Mastodon instance. It has few dependencies and so should be compatible with most Drupal sites.

Usage

The configuration of this module is in two parts, with the Mastodon needing separate configuration to the Drupal site.

Mastodon

  • Go to the /settings/applications page on your Mastodon instance and create a new application. Fill in the application name and application website with your own values. The redirect URI should be left as the default that comes with the platform.
  • You will need to set the following permissions:
    • read:statuses
    • profile
    • write:media
    • write:statuses
  • Once the app has been approved then you are ready to install the Drupal module. Copy the access key from the authentication area for later use.

Drupal

  • Install the module as normal.
  • Head to the Mastodon API configuration pages at the path /admin/config/services/mastodon. This can be found in the "Configuration > Web services" menu.
  • Enable the connection to Mastodon on this page.
  • It is possible to have Mastodon instances that you might want to connect to and it is possible to configure this in the module. Head to the "Instances" sub menu and create a new Mastodon API Instance. You will need the address of the instance and an access key.
  • You can validate the authentication for each instance using the "Validate Auth" tab.
  • Once you have the authentication configured you can then run the "Fetch configuration from instance" function on the instance auth settings form. This will pull in the instance configuration items and attempt to set any settings defined by the module.
  • Once everything is set up you can toot from the "Push Status" tab. This will ask you what instance you want to toot to.

A Note On Authentication Keys

Authentication to Mastodon is done via an access token, saved to each Mastodon API instance.

This key is never saved to the configuration of the site, doing so would be a security risk. So the key is instead saved to the Drupal State API, which means that the key lives with the database.

You can also store the key in the Drupal settings file, which gives you a mechanism where you can deploy the key to your site using a secure mechanism.

Let's say you had an instance with the machine name my_mastodon_instance. You can add the following to your settings.php file to add the auth key to that instance.

$settings['mastodon_api.my_mastodon_instance.mastodon_access_token'] = '2134';

Re-save the Mastodon API form to override the value in your settings.php file. This will write the key into the state API, overriding the value in settings.

Permissions

The following permissions are defined.

Administer Mastodon API

  • Machine name: administer mastodon api
  • Description: Configure Mastodon API settings.

Administer Mastodon API Instance

  • Machine name: administer mastodon_api_instance
  • Description: Configure Mastodon API configuration entity settings.

Sub Modules

Mastodon API Entity

This sub-module will attach the Mastodon push form to a content entity type and inject content from the entity into the push form ready for publishing. This way you can format your content ready to go and just click a button to toot.

The formatting is done via a plugin and so is fully configurable and can be overridden in your own modules.

Usage

  • Install the Mastodon API Entity sub-module.
  • Head to the Mastodon API configuration pages at the path /admin/config/services/mastodon. This can be found in the "Configuration > Web services" menu.
  • Go to the "Entity" tab and click the "Add Mastodon API Entity" action button.
  • Select the Mastodon API instance that you want these updates to go to.
  • If you want to attach the form to Content Types then select "Content Type" from the type list and then pick the bundles you want to target. Then, select the format type you want to use.
  • If the content type has image or media fields then these will be shown so you can select the default media item to use.
  • Save the form to create the configuration.
  • You can then see a "Mastodon" tab on the content item where you can create toots for that item of content. The format type you selected will dictate the contents of the box.
  • If you selected a media item to use then this will be available for selection too.
  • You can edit the contents before clicking the submit button.
Mastodon Entity Format Plugin

This plugin type exists to allow customisation of the Mastodon API push form. The following plugins exist in the sub-module.

  • Basic - This just prints the title of the content item.
  • Link - This prints the title and associated URL of the content item.
  • Token - This format type accepts a configuration setting that makes use of the token system to allow custom content to be set.

Alternatives

ActivityPub

The ActivityPub module is used to turn your Drupal site into a federated ActivityPub site. This allows users to follow content on your site from any ActivityPub site. In other words, it aggregates content on your site to ActivityPub instances where it will appear in user's timelines.

"AI" Policy

No "AI" was used in the creation of this module.

No "AI" contributions are welcome.

Supporting organizations: 
Initial development and maintenance.
Initial development.

Project information

Releases