Skip to content

triauth for MastodonOIDC

Let your members sign in to your Mastodon server with one approval on their own device, and no Mastodon passwords.

  • Community and social
  • Open source
Sign-in through
OpenID Connect bridge
Available in
Every self-hosted Mastodon, 3.5 and newer
Set up in
.env.production

About Mastodon

Mastodon is social network software that you run on your own server, in the style of Twitter. People post short messages and follow each other, including people on other Mastodon servers. Organizations run it for public communities or for their own members.

Connect Mastodon to triauth

Mastodon signs people in through the triauth OpenID Connect bridge. Once connected, the sign-in page shows a button with your domain's name under "Or log in with". Members click it, type their username, and approve on their own device. Nobody keeps a Mastodon password, and when someone leaves, removing their identity records at your domain ends their access to the server as well.

How it works

  1. Open oidc.triauth.org and enter your domain. Paste Mastodon's redirect address, https://social.example.com/auth/auth/openid_connect/callback with your own server's address in place of social.example.com, and click Connect app. The bridge gives you a client ID and a client secret.

  2. On your server, add the settings below to .env.production and restart the Mastodon services. Replace example.com with your domain, social.example.com with your server's address, and the two placeholders with the client ID and the client secret from the bridge.

    ini
    OIDC_ENABLED=true
    OIDC_DISPLAY_NAME=example.com
    OIDC_ISSUER=https://oidc.triauth.org/example.com
    OIDC_DISCOVERY=true
    OIDC_SCOPE=openid,profile,email
    OIDC_UID_FIELD=sub
    OIDC_CLIENT_ID=<client ID from the bridge>
    OIDC_CLIENT_SECRET=<client secret from the bridge>
    OIDC_REDIRECT_URI=https://social.example.com/auth/auth/openid_connect/callback
  3. Open the sign-in page and click the button with your domain's name.

Checkpoint

Mastodon's sign-in page shows a new button with your domain's name under "Or log in with". Choosing it opens a page from the bridge that asks for the username, and the person's authenticator asks them to approve.

Good to know

  • Everyone with an identity at your domain gets an account the first time they sign in. Their Mastodon username is the part of their identifier before the @. To let only one team in, limit the app to a group when you connect it.
  • Members who already have an account under the same email address are connected to it only when ALLOW_UNSAFE_AUTH_PROVIDER_REATTACH is on, which Mastodon marks as a security trade-off.
  • OMNIAUTH_ONLY=true hides the password form once everyone is over, and ONE_CLICK_SSO_LOGIN=true turns the two buttons into one.

For the person who connects the app

SettingValue
Redirect addresshttps://<your-mastodon>/auth/auth/openid_connect/callback, also set as OIDC_REDIRECT_URI
Where in Mastodon.env.production, then a restart of the web, streaming, and Sidekiq services
IssuerOIDC_ISSUER with OIDC_DISCOVERY=true, from which Mastodon reads the rest. Without discovery, OIDC_AUTH_ENDPOINT, OIDC_TOKEN_ENDPOINT, OIDC_USER_INFO_ENDPOINT, and OIDC_JWKS_URI take the addresses one by one
ScopesOIDC_SCOPE is comma separated
OptionalOIDC_USE_PKCE=true adds PKCE, and OIDC_SECURITY_ASSUME_EMAIL_IS_VERIFIED is not needed, since the bridge confirms the email address

Mastodon's own single sign-on docs page is still a placeholder. The variables above come from Mastodon's configuration source and the pull request that added OpenID Connect, which the configuration reference points to. Mastodon keeps the client secret, so leave This app can't keep a secret unticked when you connect it on the bridge.

Next steps

All logos and trademarks belong to their respective owners and do not imply affiliation or endorsement of the organization or product by triauth, nor vice versa. The content provided on this page may include information from third-party sources. We do not assume any responsibility for the completeness, correctness, or applicability of the information. You should independently verify any details before relying on them.