This documentation site is for the versions of Synapse maintained by the Matrix.org Foundation (github.com/matrix-org/synapse), available under the Apache 2.0 licence.
Synapse can be configured to use an OpenID Connect Provider (OP) for
authentication, instead of its own local password database.
Any OP should work with Synapse, as long as it supports the authorization code
flow. There are a few options for that:
start a local OP. Synapse has been tested with Hydra and
Dex. Note that for an OP to work, it should be served under a
secure (HTTPS) origin. A certificate signed with a self-signed, locally
trusted CA should work. In that case, start Synapse with a SSL_CERT_FILE
environment variable set to the path of the CA.
set up a SaaS OP, like Google, Auth0 or
Okta. Synapse has been tested with Auth0 and Google.
The OpenID integration in Synapse uses the
authlib library, which must be installed
as follows:
The relevant libraries are included in the Docker images and Debian packages
provided by matrix.org so no further action is needed.
If you installed Synapse into a virtualenv, run /path/to/env/bin/pip install matrix-synapse[oidc] to install the necessary dependencies.
For other installation mechanisms, see the documentation provided by the
maintainer.
To enable the OpenID integration, you should then add a section to the oidc_providers
setting in your configuration file.
See the configuration manual for some sample settings, as well as
the text below for example configurations for specific providers.
This lets the OpenID Connect Provider notify Synapse when a user logs out, so that Synapse can end that user session.
This feature can be enabled by setting the backchannel_logout_enabled property to true in the provider configuration, and setting the following URL as destination for Back-Channel Logout notifications in your OpenID Connect Provider: [synapse public baseurl]/_synapse/client/oidc/backchannel_logout
Azure AD can act as an OpenID Connect Provider. Register a new application under
App registrations in the Azure AD management console. The RedirectURI for your
application should point to your matrix server:
[synapse public baseurl]/_synapse/client/oidc/callback
Go to Certificates & secrets and register a new client secret. Make note of your
Directory (tenant) ID as it will be used in the Azure links.
Edit your Synapse config file and change the oidc_config section:
-idp_id:appleidp_name:Appleissuer:"https://appleid.apple.com"client_id:"your-client-id"# Set to the "identifier" for your "ServicesID"client_auth_method:"client_secret_post"client_secret_jwt_key:key_file:"/path/to/AuthKey_KEYIDCODE.p8"# point to your key filejwt_header:alg:ES256kid:"KEYIDCODE"# Set to the 10-char Key IDjwt_payload:iss:TEAMIDCODE# Set to the 10-char Team IDscopes: ["name", "email", "openid"]
authorization_endpoint:https://appleid.apple.com/auth/authorize?response_mode=form_postuser_mapping_provider:config:email_template:"{{ user.email }}"
Set the Allowed Callback URLs to [synapse public baseurl]/_synapse/client/oidc/callback
Add a rule with any name to add the preferred_username claim.
(See https://auth0.com/docs/customize/rules/create-rules for more information on how to create rules.)
oidc_providers:-idp_id:auth0idp_name:Auth0issuer:"https://your-tier.eu.auth0.com/"# TO BE FILLEDclient_id:"your-client-id"# TO BE FILLEDclient_secret:"your-client-secret"# TO BE FILLEDscopes: ["openid", "profile"]
user_mapping_provider:config:localpart_template:"{{ user.preferred_username }}"display_name_template:"{{ user.name }}"
Create a provider in Authentik, with type OAuth2/OpenID.
The parameters are:
Client Type: Confidential
JWT Algorithm: RS256
Scopes: OpenID, Email and Profile
RSA Key: Select any available key
Redirect URIs: [synapse public baseurl]/_synapse/client/oidc/callback
Create an application for synapse in Authentik and link it to the provider.
Note the slug of your application, Client ID and Client Secret.
Note: RSA keys must be used for signing for Authentik, ECC keys do not work.
Synapse config:
oidc_providers:-idp_id:authentikidp_name:authentikdiscover:trueissuer:"https://your.authentik.example.org/application/o/your-app-slug/"# TO BE FILLED: domain and slugclient_id:"your client id"# TO BE FILLEDclient_secret:"your client secret"# TO BE FILLEDscopes:-"openid"-"profile"-"email"user_mapping_provider:config:localpart_template:"{{ user.preferred_username }}"display_name_template:"{{ user.preferred_username|capitalize }}"# TO BE FILLED: If your users have names in Authentik and you want those in Synapse, this should be replaced with user.name|capitalize.
Dex is a simple, open-source OpenID Connect Provider.
Although it is designed to help building a full-blown provider with an
external database, it can be configured with static passwords in a config file.
Edit examples/config-dev.yaml config file from the Dex repo to add a client:
staticClients:-id:synapsesecret:secretredirectURIs:-'[synapse public baseurl]/_synapse/client/oidc/callback'name:'Synapse'
Run with dex serve examples/config-dev.yaml.
Synapse config:
oidc_providers:-idp_id:dexidp_name:"My Dex server"skip_verification:true# This is needed as Dex is served on an insecure endpointissuer:"http://127.0.0.1:5556/dex"client_id:"synapse"client_secret:"secret"scopes: ["openid", "profile"]
user_mapping_provider:config:localpart_template:"{{ user.name }}"display_name_template:"{{ user.name|capitalize }}"
django-oauth-toolkit is a
Django application providing out of the box all the endpoints, data and logic
needed to add OAuth2 capabilities to your Django projects. It supports
OpenID Connect too.
Configuration on Django's side:
Add an application: https://example.com/admin/oauth2_provider/application/add/ and choose parameters like this:
oidc_providers:-idp_id:django_exampleidp_name:"Django Example"issuer:"https://example.com/o/"client_id:"your-client-id"# CHANGE MEclient_secret:"your-client-secret"# CHANGE MEscopes: ["openid"]
user_profile_method:"userinfo_endpoint"# needed because oauth-toolkit does not include user information in the authorization responseuser_mapping_provider:config:localpart_template:"{{ user.email.split('@')[0] }}"display_name_template:"{{ user.first_name }}{{ user.last_name }}"email_template:"{{ user.email }}"
You will need a Facebook developer account. You can register for one
here.
On the apps page of the developer
console, "Create App", and choose "Build Connected Experiences".
Once the app is created, add "Facebook Login" and choose "Web". You don't
need to go through the whole form here.
In the left-hand menu, open "Products"/"Facebook Login"/"Settings".
Add [synapse public baseurl]/_synapse/client/oidc/callback as an OAuth Redirect
URL.
In the left-hand menu, open "Settings/Basic". Here you can copy the "App ID"
and "App Secret" for use below.
Synapse config:
-idp_id:facebookidp_name:Facebookidp_brand:"facebook"# optional: styling hint for clientsdiscover:falseissuer:"https://www.facebook.com"client_id:"your-client-id"# TO BE FILLEDclient_secret:"your-client-secret"# TO BE FILLEDscopes: ["openid", "email"]
authorization_endpoint:"https://facebook.com/dialog/oauth"token_endpoint:"https://graph.facebook.com/v9.0/oauth/access_token"jwks_uri:"https://www.facebook.com/.well-known/oauth/openid/jwks/"user_mapping_provider:config:display_name_template:"{{ user.name }}"email_template:"{{ user.email }}"
Facebook do have an OIDC discovery endpoint,
but it has a response_types_supported which excludes "code" (which we rely on, and
is even mentioned in their documentation),
so we have to disable discovery and configure the URIs manually.
GitHub is a bit special as it is not an OpenID Connect compliant provider, but
just a regular OAuth2 provider.
The /user API endpoint
can be used to retrieve information on the authenticated user. As the Synapse
login mechanism needs an attribute to uniquely identify users, and that endpoint
does not return a sub property, an alternative subject_claim has to be set.
Set the callback URL to [synapse public baseurl]/_synapse/client/oidc/callback.
Synapse config:
oidc_providers:-idp_id:githubidp_name:Githubidp_brand:"github"# optional: styling hint for clientsdiscover:falseissuer:"https://github.com/"client_id:"your-client-id"# TO BE FILLEDclient_secret:"your-client-secret"# TO BE FILLEDauthorization_endpoint:"https://github.com/login/oauth/authorize"token_endpoint:"https://github.com/login/oauth/access_token"userinfo_endpoint:"https://api.github.com/user"scopes: ["read:user"]
user_mapping_provider:config:subject_claim:"id"localpart_template:"{{ user.login }}"display_name_template:"{{ user.name }}"
Add this Callback URL: [synapse public baseurl]/_synapse/client/oidc/callback
Synapse config:
oidc_providers:-idp_id:gitlabidp_name:Gitlabidp_brand:"gitlab"# optional: styling hint for clientsissuer:"https://gitlab.com/"client_id:"your-client-id"# TO BE FILLEDclient_secret:"your-client-secret"# TO BE FILLEDclient_auth_method:"client_secret_post"scopes: ["openid", "read_user"]
user_profile_method:"userinfo_endpoint"user_mapping_provider:config:localpart_template:'{{ user.nickname }}'display_name_template:'{{ user.name }}'
Gitea is, like Github, not an OpenID provider, but just an OAuth2 provider.
The /user API endpoint
can be used to retrieve information on the authenticated user. As the Synapse
login mechanism needs an attribute to uniquely identify users, and that endpoint
does not return a sub property, an alternative subject_claim has to be set.
Create a new application.
Add this Callback URL: [synapse public baseurl]/_synapse/client/oidc/callback
Synapse config:
oidc_providers:-idp_id:giteaidp_name:Giteadiscover:falseissuer:"https://your-gitea.com/"client_id:"your-client-id"# TO BE FILLEDclient_secret:"your-client-secret"# TO BE FILLEDclient_auth_method:client_secret_postscopes: [] # Gitea doesn't support Scopesauthorization_endpoint:"https://your-gitea.com/login/oauth/authorize"token_endpoint:"https://your-gitea.com/login/oauth/access_token"userinfo_endpoint:"https://your-gitea.com/api/v1/user"user_mapping_provider:config:subject_claim:"id"localpart_template:"{{ user.login }}"display_name_template:"{{ user.full_name }}"
Google is an OpenID certified authentication and authorisation provider.
Set up a project in the Google API Console (see
documentation).
Add an "OAuth Client ID" for a Web Application under "Credentials".
Copy the Client ID and Client Secret, and add the following to your synapse config:
oidc_providers:-idp_id:googleidp_name:Googleidp_brand:"google"# optional: styling hint for clientsissuer:"https://accounts.google.com/"client_id:"your-client-id"# TO BE FILLEDclient_secret:"your-client-secret"# TO BE FILLEDscopes: ["openid", "profile", "email"] # email is optional, read belowuser_mapping_provider:config:localpart_template:"{{ user.given_name|lower }}"display_name_template:"{{ user.name }}"email_template:"{{ user.email }}"# needs "email" in scopes above
Back in the Google console, add this Authorized redirect URI: [synapse public baseurl]/_synapse/client/oidc/callback.
Keycloak is an opensource IdP maintained by Red Hat.
Keycloak supports OIDC Back-Channel Logout, which sends logout notification to Synapse, so that Synapse users get logged out when they log out from Keycloak.
This can be optionally enabled by setting backchannel_logout_enabled to true in the Synapse configuration, and by setting the "Backchannel Logout URL" in Keycloak.
Create an OpenID Connect Relying Parties in LemonLDAP::NG
The parameters are:
Client ID under the basic menu of the new Relying Parties (Options > Basic > Client ID)
Client secret (Options > Basic > Client secret)
JWT Algorithm: RS256 within the security menu of the new Relying Parties
(Options > Security > ID Token signature algorithm and Options > Security > Access Token signature algorithm)
Scopes: OpenID, Email and Profile
Allowed redirection addresses for login (Options > Basic > Allowed redirection addresses for login ) :
[synapse public baseurl]/_synapse/client/oidc/callback
Synapse config:
oidc_providers:-idp_id:lemonldapidp_name:lemonldapdiscover:trueissuer:"https://auth.example.org/"# TO BE FILLED: replace with your domainclient_id:"your client id"# TO BE FILLEDclient_secret:"your client secret"# TO BE FILLEDscopes:-"openid"-"profile"-"email"user_mapping_provider:config:localpart_template:"{{ user.preferred_username }}}"# TO BE FILLED: If your users have names in LemonLDAP::NG and you want those in Synapse, this should be replaced with user.name|capitalize or any valid filter.display_name_template:"{{ user.preferred_username|capitalize }}"
Mastodon instances provide an OAuth API, allowing those instances to be used as a single sign-on provider for Synapse.
The first step is to register Synapse as an application with your Mastodon instance, using the Create an application API (see also here). There are several ways to do this, but in the example below we are using CURL.
This example assumes that:
the Mastodon instance website URL is https://your.mastodon.instance.url, and
Synapse will be registered as an app named my_synapse_app.
Send the following request, substituting the value of synapse_public_baseurl from your Synapse installation.
curl -d "client_name=my_synapse_app&redirect_uris=https://[synapse_public_baseurl]/_synapse/client/oidc/callback" -X POST https://your.mastodon.instance.url/api/v1/apps
You should receive a response similar to the following. Make sure to save it.
As the Synapse login mechanism needs an attribute to uniquely identify users, and Mastodon's endpoint does not return a sub property, an alternative subject_template has to be set. Your Synapse configuration should include the following:
Add this OAuth Redirect URL: [synapse public baseurl]/_synapse/client/oidc/callback
Synapse config:
oidc_providers:-idp_id:twitchidp_name:Twitchissuer:"https://id.twitch.tv/oauth2/"client_id:"your-client-id"# TO BE FILLEDclient_secret:"your-client-secret"# TO BE FILLEDclient_auth_method:"client_secret_post"user_mapping_provider:config:localpart_template:"{{ user.preferred_username }}"display_name_template:"{{ user.name }}"
Enable user authentication and under "Type of App" choose "Web App, Automated App or Bot".
Under "App info" set the callback URL to [synapse public baseurl]/_synapse/client/oidc/callback.
Obtain the OAuth 2.0 credentials under the "Keys and tokens" tab, copy the "OAuth 2.0 Client ID and Client Secret"
Synapse config:
oidc_providers:-idp_id:twitteridp_name:Twitteridp_brand:"twitter"# optional: styling hint for clientsdiscover:false# Twitter is not OpenID compliant.issuer:"https://twitter.com/"client_id:"your-client-id"# TO BE FILLEDclient_secret:"your-client-secret"# TO BE FILLEDpkce_method:"always"# offline.access providers refresh tokens, tweet.read and users.read needed for userinfo request.scopes: ["offline.access", "tweet.read", "users.read"]
authorization_endpoint:https://twitter.com/i/oauth2/authorizetoken_endpoint:https://api.twitter.com/2/oauth2/tokenuserinfo_endpoint:https://api.twitter.com/2/users/me?user.fields=profile_image_urluser_mapping_provider:config:subject_template:"{{ user.data.id }}"localpart_template:"{{ user.data.username }}"display_name_template:"{{ user.data.name }}"picture_template:"{{ user.data.profile_image_url }}"