Mastodon and Keycloak SAML
I managed to get Mastodon SAML sign-ins working with Keycloak. Since I never bothered to learn anything about SAML, this made it difficult. But I persevered. I would like to share what finally made it work.
Mastodon
Mastodon’s .env.production
file:
|
|
Get the SAML_IDP_CERT
from Keycloak’s Realm Settings -> Keys -> Certificate
Keycloak
Create a new SAML client with the following:
Settings
Field | Value |
---|---|
Client ID | mastodon |
Include AuthnStatement | ON |
Sign Documents | ON |
Sign Assertions | ON |
Name ID Format | username |
Valid Redirect URIs | https://{your mastodon server}/auth/auth/saml/callback |
Base URL | https://{your mastodon server} |
Mappers
Mapper Type | Property | SAML Attribute Name | SAML Attribute NameFormat |
---|---|---|---|
User Property | lastName | last_name | Basic |
User Property | Basic | ||
User Property | firstName | first_name | Basic |
User Property | uid | uid | Basic |
You could probably turn on Encrypted Assertions if you filled in the SAML_CERT
and SAML_PRIVATE_KEY
for Mastodon.
Keep in mind this is just one way of setting it up and naming the fields. But after looking at Mastodon’s code and both servers’ debug logs for a while, this seems to work for me.