Sign-in and accounts
This page is for owners who want to know how accounts work on their site. After reading it you can explain why every site account is a Matrix account, what happens during a sign-in, why "linking Twitch" is not "signing in with Twitch", and what is and is not possible with other sign-in providers.
Every account lives on your own homeserver, and every sign-in goes through one sign-in service, MAS (Matrix Authentication Service). How a viewer makes and manages an account is in Your account.
A site account is a Matrix account
When someone makes an account on your site, MAS makes it on your homeserver, and its name is a Matrix ID such as @casey:example.com. The website keeps a profile row for each account, and that row's key is the Matrix ID. There is no second, separate website account.
One account for both is what lets the parts fit together:
- The same account posts in site chat, joins your community rooms, sends direct messages, and can sign in to any Matrix app, such as Element, with the same name and password.
- End-to-end encryption keys belong to Matrix devices, so each browser a person signs in from is a Matrix device of that account.
- Deleting an account from the site also deactivates and erases the Matrix account.
Where Matrix is needed
For accounts, always. There is no way to sign in to the site that does not go through MAS, and no account that is not a Matrix account. The homeserver is part of every install and cannot be switched off.
For chat messages, only partly. A message typed in site chat is not a Matrix message. It goes from the website to stream-api and into the site's own table, like every platform's chat (see How chat flows). Matrix carries the community rooms and direct messages. Site chat uses the Matrix account only to know who is typing.
How a sign-in works
sequenceDiagram
participant B as Browser
participant W as Website
participant M as MAS (matrix.example.com/auth)
participant S as Synapse
B->>W: Sign in
W->>B: Go to MAS, with a one-time challenge
B->>M: Password (or sign up)
M->>B: Back to the website with a code
B->>W: The code
W->>M: Exchange the code for tokens
W->>S: Who is this? (with the token)
W->>B: Signed in, plus a Matrix session for this device
- The website starts an OAuth 2.0 sign-in with MAS, using PKCE (a one-time challenge that stops a stolen code from being used elsewhere) and a device id for this browser.
- The browser goes to MAS's own page at
matrix.example.com/auth. The password is typed there, never on the website, and MAS stores it hashed with Argon2id. - MAS sends the browser back to the website with a code. The website is MAS's one registered client, and its return address is the only one allowed, so the code cannot be sent anywhere else.
- The website trades the code for tokens, asks Synapse which account they belong to, stores the Matrix tokens for this device (encrypted), and gives the browser its site session cookie.
- From then on the website refreshes those tokens in the background, so the person stays signed in. An account on your own homeserver always refreshes through the website's own client at MAS.
MAS, not Synapse, owns accounts and passwords: the homeserver hands every login to MAS. That is the current Matrix design for sign-in (see the MAS documentation and areweoidcyet.com), and it is why a Matrix app's login also lands on MAS's page.
Sign-up and passwords
Sign-up is closed until setup is finished, and then follows your switch in Admin Panel → Site → Community, card Federation and sign-up, switch Let people make accounts. The details are on The homeserver → Sign-up. Sign-up asks for a username and password only, unless you have set a mail server in Admin Panel → Site → Site, card Mail: then it also asks for an address and confirms it by mail, and the sign-in page offers "Forgot password?". Without a mail server (a new install) there is no "forgot password" by email; you reset a member's password on the server, as Resetting a password shows.
The setup pages make your admin account directly, through MAS's admin API, which listens only inside the server.
Platform accounts are linked, not signed in with
Linking a platform account and signing in are two separate things. A viewer first has a site account, then links platform accounts to it. Linking uses the platform's OAuth sign-in, but only to prove the account is theirs and to get the permissions the site needs to post for them. It does not create a site account or sign anyone in. The Continue with Twitch (or Google, Discord) button you can switch on is the other thing: it signs a person in to their site account and links no platform account (see Other sign-in providers).
That keeps one place for passwords and sessions (MAS), and it is what makes the identity model work: a linked platform account is joined to the person behind the site account. See One person, many accounts and Linking your platforms.
Accounts from other Matrix servers
Someone who already has a Matrix account elsewhere, such as @casey:other.example, can sign in to your site with it, through "use a Matrix account from another server" on the sign-in page. This is off by default, and while it is off the sign-in page does not offer it. Change it in Admin Panel → Site → Site, card Sign-in from other servers: off, on (any server not on the deny list) or allowlist (only the servers you list). Server names are matched exactly, and a change applies at once, to people already signed in too.
How it works: the website looks up the other server's address from its .well-known file, finds that server's OAuth sign-in service, registers itself there as a client on the spot (dynamic client registration), and sends the person to sign in on their own server. So it only works with servers that use OAuth sign-in and allow dynamic registration. Anything else gets a message saying the server does not support that kind of login yet.
The account still lives on the other server; your site keeps a profile row for it. Joining your community rooms with such an account also needs federation on, because the account's own server has to talk to yours.
Other sign-in providers (Google, Discord, Authentik, …)
Google, Discord, Twitch and one OpenID Connect server of your own (Authentik, Keycloak, Zitadel…) can each be switched on in Admin Panel → Site → Site, card Sign-in providers. All are off on a new install. The steps, and what a viewer sees: Admin Panel: Site.
A provider plugs in at MAS, not at Synapse or the website. MAS supports upstream OAuth 2.0 and OpenID Connect providers: when you save the card, your server writes the providers into MAS's configuration, and MAS's sign-in page then offers "Continue with …". On first use MAS creates the Matrix account and links it to that provider. The website always signs in through MAS, so nothing else changes. A provider never brings in an email address: a person who wants one adds it on the sign-in service's account page.
Add providers through the card, not by hand. sudo blackbranch render writes MAS's configuration in full from your settings, and it runs on every sudo blackbranch up, every update and restore, at the end of setup, and when some settings change (such as sign-up and federation), so a hand edit is replaced at the next one.
In this release, people sign in with a password on your own homeserver, with a provider you switched on, or, if you switch it on, with an account on another Matrix server.