Skip to main content
Hayon connects to Mastodon using OAuth 2.0 against a single Mastodon instance configured at deployment time via the MASTODON_INSTANCE_URL environment variable. Because Mastodon is federated, each instance runs its own OAuth server — Hayon’s integration is instance-specific.
Hayon connects to one pre-configured Mastodon instance. If your account is on a different instance (e.g. fosstodon.org instead of mastodon.social), you must update the server’s MASTODON_INSTANCE_URL environment variable and re-register the OAuth app on that instance. See Environment variables for details.

How Mastodon auth works

Mastodon implements a standard OAuth 2.0 authorization code flow, but scoped to a specific instance:
  1. Hayon redirects you to {MASTODON_INSTANCE_URL}/oauth/authorize with the code response type and the requested scopes.
  2. You authorize on the Mastodon instance.
  3. The instance redirects back to Hayon’s callback with an authorization code.
  4. Hayon exchanges the code for an access token via POST {MASTODON_INSTANCE_URL}/oauth/token.
  5. Hayon fetches your profile from GET {MASTODON_INSTANCE_URL}/api/v1/accounts/verify_credentials.
The access token is a bearer token passed in Authorization: Bearer {token} headers for all subsequent API calls.

Connecting your Mastodon account

1

Verify your instance

Confirm that the Mastodon instance configured in your Hayon deployment (MASTODON_INSTANCE_URL) is the one your account is on. If not, contact your administrator to update the configuration.
2

Open platform settings

In the Hayon dashboard, navigate to Settings > Connected accounts and click Connect next to Mastodon.
3

Hayon generates the auth URL

Hayon calls GET /api/platform/mastodon/connect, which constructs an authorization URL pointing to your configured Mastodon instance with the required scopes and your Hayon user ID as the state parameter.
4

Authorize on Mastodon

Your browser opens your Mastodon instance’s authorization page. Review the requested permissions and click Authorize.
5

Callback and token exchange

Mastodon redirects back to GET /api/platform/mastodon/callback. Hayon extracts the code and state, exchanges the code for an access token, and fetches your account profile.
6

Profile stored

Your Mastodon username, display name, avatar, account ID, and the instance URL are stored in your SocialAccount document.
7

Redirect to settings

You are redirected to /settings where your connected Mastodon account appears.

Required OAuth scopes

Hayon requests the following Mastodon scopes:
ScopePurpose
readRead account information, home timeline, notifications
writePublish posts (statuses), upload media, manage follows
pushSubscribe to push notifications (for delivery status updates)
Mastodon’s scope model uses broad top-level scopes (read, write, push). More granular sub-scopes (e.g. write:statuses, read:accounts) can be used if you want to restrict permissions — update MASTODON_SCOPES in the service if your deployment requires tighter access control.

Instance URL requirements

The Mastodon instance URL must meet these requirements:
  • Must be a reachable HTTPS URL (e.g. https://mastodon.social).
  • Must not include a trailing slash — the service appends paths like /oauth/authorize directly.
  • Must have an OAuth application registered (Hayon reads MASTODON_CLIENT_KEY and MASTODON_CLIENT_SECRET from environment variables).
  • The registered application’s redirect URI must match MASTODON_CALLBACK_URL.
To register an OAuth app on a Mastodon instance, go to {instance_url}/settings/applications and create a new application with the required scopes and redirect URI. The client key and secret are then set as MASTODON_CLIENT_KEY and MASTODON_CLIENT_SECRET in Hayon’s environment.

What Hayon stores

FieldDescription
connectedtrue once authorized
instanceUrlThe Mastodon instance URL at time of connection
accountIdYour numeric Mastodon account ID on the instance
auth.accessTokenBearer token for API requests
profile.handleYour Mastodon username (without the @instance part)
profile.displayNameYour Mastodon display name
profile.avatarAvatar URL returned by the instance

Supported post types

Mastodon posts are called statuses. Hayon supports:
Content typeSupported
Text statusesYes
Statuses with imagesYes (up to 4 attachments)
Statuses with videoNo
Content warnings (spoiler_text)No
PollsNo
Boosting / rebloggingNo

Character limits

Character limits vary by Mastodon instance. The most common default is:
  • Default limit: 500 characters per status.
  • Extended instances: Some instances (e.g. mastodon.social) allow up to 500 characters; others like fosstodon.org match this default.
  • Custom instances: Self-hosted instances can configure any limit. Check your instance’s /api/v1/instance endpoint for the max_toot_chars field.
Hayon does not query the instance character limit dynamically. Posts that exceed the instance’s configured limit will be rejected by the Mastodon API. Ensure your post content stays within the safe 500-character default.

Media constraints

  • Image formats: JPEG, PNG, GIF, WebP (instance-dependent).
  • Maximum file size: Typically 8–16 MB per file, configured per instance.
  • Attachments per status: Up to 4 media attachments.
  • Videos: Not currently supported in Hayon’s Mastodon integration.
  • Sensitivity flag: Hayon does not currently set the sensitive flag on media — this can be added per instance policy.

Refreshing your profile

To refresh your stored Mastodon profile without reconnecting:
GET /api/platform/mastodon/refresh
Authorization: Bearer <hayon-jwt>
This calls GET {instanceUrl}/api/v1/accounts/verify_credentials with your stored access token and updates your username, display name, and avatar.

Disconnecting

To disconnect Mastodon, navigate to Settings > Connected accounts and click Disconnect next to Mastodon, or call:
DELETE /api/platform/mastodon/disconnect
Authorization: Bearer <hayon-jwt>
This clears the access token, account ID, instance URL, and profile data, and sets connected: false.
Hayon does not revoke the access token on the Mastodon instance when you disconnect. To fully remove Hayon’s access, go to {instance_url}/settings/applications and revoke the token there.

Troubleshooting

This occurs if you denied access or the redirect URI does not match the one registered on the Mastodon instance. Verify that MASTODON_CALLBACK_URL exactly matches the redirect URI in your Mastodon app settings.
The access token may have been revoked on the instance side, or the token has expired (instance-specific). Disconnect Mastodon and reconnect to obtain a fresh access token.
Hayon always connects to the instance configured in MASTODON_INSTANCE_URL. If your account is on a different instance, you need to update the environment variable and re-register the OAuth application on the correct instance before reconnecting.
Changing your Mastodon account password or revoking tokens in your instance settings invalidates the stored access token. Reconnect Mastodon to obtain a new one.

Build docs developers (and LLMs) love