Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. # Configuring Synapse to authenticate against an OpenID Connect provider
  2. Synapse can be configured to use an OpenID Connect Provider (OP) for
  3. authentication, instead of its own local password database.
  4. Any OP should work with Synapse, as long as it supports the authorization code
  5. flow. There are a few options for that:
  6. - start a local OP. Synapse has been tested with [Hydra][hydra] and
  7. [Dex][dex-idp]. Note that for an OP to work, it should be served under a
  8. secure (HTTPS) origin. A certificate signed with a self-signed, locally
  9. trusted CA should work. In that case, start Synapse with a `SSL_CERT_FILE`
  10. environment variable set to the path of the CA.
  11. - set up a SaaS OP, like [Google][google-idp], [Auth0][auth0] or
  12. [Okta][okta]. Synapse has been tested with Auth0 and Google.
  13. It may also be possible to use other OAuth2 providers which provide the
  14. [authorization code grant type](https://tools.ietf.org/html/rfc6749#section-4.1),
  15. such as [Github][github-idp].
  16. [google-idp]: https://developers.google.com/identity/protocols/oauth2/openid-connect
  17. [auth0]: https://auth0.com/
  18. [authentik]: https://goauthentik.io/
  19. [lemonldap]: https://lemonldap-ng.org/
  20. [okta]: https://www.okta.com/
  21. [dex-idp]: https://github.com/dexidp/dex
  22. [keycloak-idp]: https://www.keycloak.org/docs/latest/server_admin/#sso-protocols
  23. [hydra]: https://www.ory.sh/docs/hydra/
  24. [github-idp]: https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps
  25. ## Preparing Synapse
  26. The OpenID integration in Synapse uses the
  27. [`authlib`](https://pypi.org/project/Authlib/) library, which must be installed
  28. as follows:
  29. * The relevant libraries are included in the Docker images and Debian packages
  30. provided by `matrix.org` so no further action is needed.
  31. * If you installed Synapse into a virtualenv, run `/path/to/env/bin/pip
  32. install matrix-synapse[oidc]` to install the necessary dependencies.
  33. * For other installation mechanisms, see the documentation provided by the
  34. maintainer.
  35. To enable the OpenID integration, you should then add a section to the `oidc_providers`
  36. setting in your configuration file.
  37. See the [configuration manual](usage/configuration/config_documentation.md#oidc_providers) for some sample settings, as well as
  38. the text below for example configurations for specific providers.
  39. ## OIDC Back-Channel Logout
  40. Synapse supports receiving [OpenID Connect Back-Channel Logout](https://openid.net/specs/openid-connect-backchannel-1_0.html) notifications.
  41. This lets the OpenID Connect Provider notify Synapse when a user logs out, so that Synapse can end that user session.
  42. 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`
  43. ## Sample configs
  44. Here are a few configs for providers that should work with Synapse.
  45. ### Microsoft Azure Active Directory
  46. Azure AD can act as an OpenID Connect Provider. Register a new application under
  47. *App registrations* in the Azure AD management console. The RedirectURI for your
  48. application should point to your matrix server:
  49. `[synapse public baseurl]/_synapse/client/oidc/callback`
  50. Go to *Certificates & secrets* and register a new client secret. Make note of your
  51. Directory (tenant) ID as it will be used in the Azure links.
  52. Edit your Synapse config file and change the `oidc_config` section:
  53. ```yaml
  54. oidc_providers:
  55. - idp_id: microsoft
  56. idp_name: Microsoft
  57. issuer: "https://login.microsoftonline.com/<tenant id>/v2.0"
  58. client_id: "<client id>"
  59. client_secret: "<client secret>"
  60. scopes: ["openid", "profile"]
  61. authorization_endpoint: "https://login.microsoftonline.com/<tenant id>/oauth2/v2.0/authorize"
  62. token_endpoint: "https://login.microsoftonline.com/<tenant id>/oauth2/v2.0/token"
  63. userinfo_endpoint: "https://graph.microsoft.com/oidc/userinfo"
  64. user_mapping_provider:
  65. config:
  66. localpart_template: "{{ user.preferred_username.split('@')[0] }}"
  67. display_name_template: "{{ user.name }}"
  68. ```
  69. ### Apple
  70. Configuring "Sign in with Apple" (SiWA) requires an Apple Developer account.
  71. You will need to create a new "Services ID" for SiWA, and create and download a
  72. private key with "SiWA" enabled.
  73. As well as the private key file, you will need:
  74. * Client ID: the "identifier" you gave the "Services ID"
  75. * Team ID: a 10-character ID associated with your developer account.
  76. * Key ID: the 10-character identifier for the key.
  77. [Apple's developer documentation](https://help.apple.com/developer-account/?lang=en#/dev77c875b7e)
  78. has more information on setting up SiWA.
  79. The synapse config will look like this:
  80. ```yaml
  81. - idp_id: apple
  82. idp_name: Apple
  83. issuer: "https://appleid.apple.com"
  84. client_id: "your-client-id" # Set to the "identifier" for your "ServicesID"
  85. client_auth_method: "client_secret_post"
  86. client_secret_jwt_key:
  87. key_file: "/path/to/AuthKey_KEYIDCODE.p8" # point to your key file
  88. jwt_header:
  89. alg: ES256
  90. kid: "KEYIDCODE" # Set to the 10-char Key ID
  91. jwt_payload:
  92. iss: TEAMIDCODE # Set to the 10-char Team ID
  93. scopes: ["name", "email", "openid"]
  94. authorization_endpoint: https://appleid.apple.com/auth/authorize?response_mode=form_post
  95. user_mapping_provider:
  96. config:
  97. email_template: "{{ user.email }}"
  98. ```
  99. ### Auth0
  100. [Auth0][auth0] is a hosted SaaS IdP solution.
  101. 1. Create a regular web application for Synapse
  102. 2. Set the Allowed Callback URLs to `[synapse public baseurl]/_synapse/client/oidc/callback`
  103. 3. Add a rule with any name to add the `preferred_username` claim.
  104. (See https://auth0.com/docs/customize/rules/create-rules for more information on how to create rules.)
  105. <details>
  106. <summary>Code sample</summary>
  107. ```js
  108. function addPersistenceAttribute(user, context, callback) {
  109. user.user_metadata = user.user_metadata || {};
  110. user.user_metadata.preferred_username = user.user_metadata.preferred_username || user.user_id;
  111. context.idToken.preferred_username = user.user_metadata.preferred_username;
  112. auth0.users.updateUserMetadata(user.user_id, user.user_metadata)
  113. .then(function(){
  114. callback(null, user, context);
  115. })
  116. .catch(function(err){
  117. callback(err);
  118. });
  119. }
  120. ```
  121. </details>
  122. Synapse config:
  123. ```yaml
  124. oidc_providers:
  125. - idp_id: auth0
  126. idp_name: Auth0
  127. issuer: "https://your-tier.eu.auth0.com/" # TO BE FILLED
  128. client_id: "your-client-id" # TO BE FILLED
  129. client_secret: "your-client-secret" # TO BE FILLED
  130. scopes: ["openid", "profile"]
  131. user_mapping_provider:
  132. config:
  133. localpart_template: "{{ user.preferred_username }}"
  134. display_name_template: "{{ user.name }}"
  135. ```
  136. ### Authentik
  137. [Authentik][authentik] is an open-source IdP solution.
  138. 1. Create a provider in Authentik, with type OAuth2/OpenID.
  139. 2. The parameters are:
  140. - Client Type: Confidential
  141. - JWT Algorithm: RS256
  142. - Scopes: OpenID, Email and Profile
  143. - RSA Key: Select any available key
  144. - Redirect URIs: `[synapse public baseurl]/_synapse/client/oidc/callback`
  145. 3. Create an application for synapse in Authentik and link it to the provider.
  146. 4. Note the slug of your application, Client ID and Client Secret.
  147. Note: RSA keys must be used for signing for Authentik, ECC keys do not work.
  148. Synapse config:
  149. ```yaml
  150. oidc_providers:
  151. - idp_id: authentik
  152. idp_name: authentik
  153. discover: true
  154. issuer: "https://your.authentik.example.org/application/o/your-app-slug/" # TO BE FILLED: domain and slug
  155. client_id: "your client id" # TO BE FILLED
  156. client_secret: "your client secret" # TO BE FILLED
  157. scopes:
  158. - "openid"
  159. - "profile"
  160. - "email"
  161. user_mapping_provider:
  162. config:
  163. localpart_template: "{{ user.preferred_username }}"
  164. 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.
  165. ```
  166. ### Dex
  167. [Dex][dex-idp] is a simple, open-source OpenID Connect Provider.
  168. Although it is designed to help building a full-blown provider with an
  169. external database, it can be configured with static passwords in a config file.
  170. Follow the [Getting Started guide](https://dexidp.io/docs/getting-started/)
  171. to install Dex.
  172. Edit `examples/config-dev.yaml` config file from the Dex repo to add a client:
  173. ```yaml
  174. staticClients:
  175. - id: synapse
  176. secret: secret
  177. redirectURIs:
  178. - '[synapse public baseurl]/_synapse/client/oidc/callback'
  179. name: 'Synapse'
  180. ```
  181. Run with `dex serve examples/config-dev.yaml`.
  182. Synapse config:
  183. ```yaml
  184. oidc_providers:
  185. - idp_id: dex
  186. idp_name: "My Dex server"
  187. skip_verification: true # This is needed as Dex is served on an insecure endpoint
  188. issuer: "http://127.0.0.1:5556/dex"
  189. client_id: "synapse"
  190. client_secret: "secret"
  191. scopes: ["openid", "profile"]
  192. user_mapping_provider:
  193. config:
  194. localpart_template: "{{ user.name }}"
  195. display_name_template: "{{ user.name|capitalize }}"
  196. ```
  197. ### Django OAuth Toolkit
  198. [django-oauth-toolkit](https://github.com/jazzband/django-oauth-toolkit) is a
  199. Django application providing out of the box all the endpoints, data and logic
  200. needed to add OAuth2 capabilities to your Django projects. It supports
  201. [OpenID Connect too](https://django-oauth-toolkit.readthedocs.io/en/latest/oidc.html).
  202. Configuration on Django's side:
  203. 1. Add an application: `https://example.com/admin/oauth2_provider/application/add/` and choose parameters like this:
  204. * `Redirect uris`: `https://synapse.example.com/_synapse/client/oidc/callback`
  205. * `Client type`: `Confidential`
  206. * `Authorization grant type`: `Authorization code`
  207. * `Algorithm`: `HMAC with SHA-2 256`
  208. 2. You can [customize the claims](https://django-oauth-toolkit.readthedocs.io/en/latest/oidc.html#customizing-the-oidc-responses) Django gives to synapse (optional):
  209. <details>
  210. <summary>Code sample</summary>
  211. ```python
  212. class CustomOAuth2Validator(OAuth2Validator):
  213. def get_additional_claims(self, request):
  214. return {
  215. "sub": request.user.email,
  216. "email": request.user.email,
  217. "first_name": request.user.first_name,
  218. "last_name": request.user.last_name,
  219. }
  220. ```
  221. </details>
  222. Your synapse config is then:
  223. ```yaml
  224. oidc_providers:
  225. - idp_id: django_example
  226. idp_name: "Django Example"
  227. issuer: "https://example.com/o/"
  228. client_id: "your-client-id" # CHANGE ME
  229. client_secret: "your-client-secret" # CHANGE ME
  230. scopes: ["openid"]
  231. user_profile_method: "userinfo_endpoint" # needed because oauth-toolkit does not include user information in the authorization response
  232. user_mapping_provider:
  233. config:
  234. localpart_template: "{{ user.email.split('@')[0] }}"
  235. display_name_template: "{{ user.first_name }} {{ user.last_name }}"
  236. email_template: "{{ user.email }}"
  237. ```
  238. ### Facebook
  239. 0. You will need a Facebook developer account. You can register for one
  240. [here](https://developers.facebook.com/async/registration/).
  241. 1. On the [apps](https://developers.facebook.com/apps/) page of the developer
  242. console, "Create App", and choose "Build Connected Experiences".
  243. 2. Once the app is created, add "Facebook Login" and choose "Web". You don't
  244. need to go through the whole form here.
  245. 3. In the left-hand menu, open "Products"/"Facebook Login"/"Settings".
  246. * Add `[synapse public baseurl]/_synapse/client/oidc/callback` as an OAuth Redirect
  247. URL.
  248. 4. In the left-hand menu, open "Settings/Basic". Here you can copy the "App ID"
  249. and "App Secret" for use below.
  250. Synapse config:
  251. ```yaml
  252. - idp_id: facebook
  253. idp_name: Facebook
  254. idp_brand: "facebook" # optional: styling hint for clients
  255. discover: false
  256. issuer: "https://www.facebook.com"
  257. client_id: "your-client-id" # TO BE FILLED
  258. client_secret: "your-client-secret" # TO BE FILLED
  259. scopes: ["openid", "email"]
  260. authorization_endpoint: "https://facebook.com/dialog/oauth"
  261. token_endpoint: "https://graph.facebook.com/v9.0/oauth/access_token"
  262. jwks_uri: "https://www.facebook.com/.well-known/oauth/openid/jwks/"
  263. user_mapping_provider:
  264. config:
  265. display_name_template: "{{ user.name }}"
  266. email_template: "{{ user.email }}"
  267. ```
  268. Relevant documents:
  269. * [Manually Build a Login Flow](https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow)
  270. * [Using Facebook's Graph API](https://developers.facebook.com/docs/graph-api/using-graph-api/)
  271. * [Reference to the User endpoint](https://developers.facebook.com/docs/graph-api/reference/user)
  272. Facebook do have an [OIDC discovery endpoint](https://www.facebook.com/.well-known/openid-configuration),
  273. but it has a `response_types_supported` which excludes "code" (which we rely on, and
  274. is even mentioned in their [documentation](https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow#login)),
  275. so we have to disable discovery and configure the URIs manually.
  276. ### GitHub
  277. [GitHub][github-idp] is a bit special as it is not an OpenID Connect compliant provider, but
  278. just a regular OAuth2 provider.
  279. The [`/user` API endpoint](https://developer.github.com/v3/users/#get-the-authenticated-user)
  280. can be used to retrieve information on the authenticated user. As the Synapse
  281. login mechanism needs an attribute to uniquely identify users, and that endpoint
  282. does not return a `sub` property, an alternative `subject_claim` has to be set.
  283. 1. Create a new OAuth application: [https://github.com/settings/applications/new](https://github.com/settings/applications/new).
  284. 2. Set the callback URL to `[synapse public baseurl]/_synapse/client/oidc/callback`.
  285. Synapse config:
  286. ```yaml
  287. oidc_providers:
  288. - idp_id: github
  289. idp_name: Github
  290. idp_brand: "github" # optional: styling hint for clients
  291. discover: false
  292. issuer: "https://github.com/"
  293. client_id: "your-client-id" # TO BE FILLED
  294. client_secret: "your-client-secret" # TO BE FILLED
  295. authorization_endpoint: "https://github.com/login/oauth/authorize"
  296. token_endpoint: "https://github.com/login/oauth/access_token"
  297. userinfo_endpoint: "https://api.github.com/user"
  298. scopes: ["read:user"]
  299. user_mapping_provider:
  300. config:
  301. subject_claim: "id"
  302. localpart_template: "{{ user.login }}"
  303. display_name_template: "{{ user.name }}"
  304. ```
  305. ### GitLab
  306. 1. Create a [new application](https://gitlab.com/profile/applications).
  307. 2. Add the `read_user` and `openid` scopes.
  308. 3. Add this Callback URL: `[synapse public baseurl]/_synapse/client/oidc/callback`
  309. Synapse config:
  310. ```yaml
  311. oidc_providers:
  312. - idp_id: gitlab
  313. idp_name: Gitlab
  314. idp_brand: "gitlab" # optional: styling hint for clients
  315. issuer: "https://gitlab.com/"
  316. client_id: "your-client-id" # TO BE FILLED
  317. client_secret: "your-client-secret" # TO BE FILLED
  318. client_auth_method: "client_secret_post"
  319. scopes: ["openid", "read_user"]
  320. user_profile_method: "userinfo_endpoint"
  321. user_mapping_provider:
  322. config:
  323. localpart_template: '{{ user.nickname }}'
  324. display_name_template: '{{ user.name }}'
  325. ```
  326. ### Gitea
  327. Gitea is, like Github, not an OpenID provider, but just an OAuth2 provider.
  328. The [`/user` API endpoint](https://try.gitea.io/api/swagger#/user/userGetCurrent)
  329. can be used to retrieve information on the authenticated user. As the Synapse
  330. login mechanism needs an attribute to uniquely identify users, and that endpoint
  331. does not return a `sub` property, an alternative `subject_claim` has to be set.
  332. 1. Create a new application.
  333. 2. Add this Callback URL: `[synapse public baseurl]/_synapse/client/oidc/callback`
  334. Synapse config:
  335. ```yaml
  336. oidc_providers:
  337. - idp_id: gitea
  338. idp_name: Gitea
  339. discover: false
  340. issuer: "https://your-gitea.com/"
  341. client_id: "your-client-id" # TO BE FILLED
  342. client_secret: "your-client-secret" # TO BE FILLED
  343. client_auth_method: client_secret_post
  344. scopes: [] # Gitea doesn't support Scopes
  345. authorization_endpoint: "https://your-gitea.com/login/oauth/authorize"
  346. token_endpoint: "https://your-gitea.com/login/oauth/access_token"
  347. userinfo_endpoint: "https://your-gitea.com/api/v1/user"
  348. user_mapping_provider:
  349. config:
  350. subject_claim: "id"
  351. localpart_template: "{{ user.login }}"
  352. display_name_template: "{{ user.full_name }}"
  353. ```
  354. ### Google
  355. [Google][google-idp] is an OpenID certified authentication and authorisation provider.
  356. 1. Set up a project in the Google API Console (see
  357. [documentation](https://developers.google.com/identity/protocols/oauth2/openid-connect#appsetup)).
  358. 3. Add an "OAuth Client ID" for a Web Application under "Credentials".
  359. 4. Copy the Client ID and Client Secret, and add the following to your synapse config:
  360. ```yaml
  361. oidc_providers:
  362. - idp_id: google
  363. idp_name: Google
  364. idp_brand: "google" # optional: styling hint for clients
  365. issuer: "https://accounts.google.com/"
  366. client_id: "your-client-id" # TO BE FILLED
  367. client_secret: "your-client-secret" # TO BE FILLED
  368. scopes: ["openid", "profile", "email"] # email is optional, read below
  369. user_mapping_provider:
  370. config:
  371. localpart_template: "{{ user.given_name|lower }}"
  372. display_name_template: "{{ user.name }}"
  373. email_template: "{{ user.email }}" # needs "email" in scopes above
  374. ```
  375. 4. Back in the Google console, add this Authorized redirect URI: `[synapse
  376. public baseurl]/_synapse/client/oidc/callback`.
  377. ### Keycloak
  378. [Keycloak][keycloak-idp] is an opensource IdP maintained by Red Hat.
  379. 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.
  380. 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.
  381. Follow the [Getting Started Guide](https://www.keycloak.org/guides) to install Keycloak and set up a realm.
  382. 1. Click `Clients` in the sidebar and click `Create`
  383. 2. Fill in the fields as below:
  384. | Field | Value |
  385. |-----------|-----------|
  386. | Client ID | `synapse` |
  387. | Client Protocol | `openid-connect` |
  388. 3. Click `Save`
  389. 4. Fill in the fields as below:
  390. | Field | Value |
  391. |-----------|-----------|
  392. | Client ID | `synapse` |
  393. | Enabled | `On` |
  394. | Client Protocol | `openid-connect` |
  395. | Access Type | `confidential` |
  396. | Valid Redirect URIs | `[synapse public baseurl]/_synapse/client/oidc/callback` |
  397. | Backchannel Logout URL (optional) | `[synapse public baseurl]/_synapse/client/oidc/backchannel_logout` |
  398. | Backchannel Logout Session Required (optional) | `On` |
  399. 5. Click `Save`
  400. 6. On the Credentials tab, update the fields:
  401. | Field | Value |
  402. |-------|-------|
  403. | Client Authenticator | `Client ID and Secret` |
  404. 7. Click `Regenerate Secret`
  405. 8. Copy Secret
  406. ```yaml
  407. oidc_providers:
  408. - idp_id: keycloak
  409. idp_name: "My KeyCloak server"
  410. issuer: "https://127.0.0.1:8443/realms/{realm_name}"
  411. client_id: "synapse"
  412. client_secret: "copy secret generated from above"
  413. scopes: ["openid", "profile"]
  414. user_mapping_provider:
  415. config:
  416. localpart_template: "{{ user.preferred_username }}"
  417. display_name_template: "{{ user.name }}"
  418. backchannel_logout_enabled: true # Optional
  419. ```
  420. ### LemonLDAP
  421. [LemonLDAP::NG][lemonldap] is an open-source IdP solution.
  422. 1. Create an OpenID Connect Relying Parties in LemonLDAP::NG
  423. 2. The parameters are:
  424. - Client ID under the basic menu of the new Relying Parties (`Options > Basic >
  425. Client ID`)
  426. - Client secret (`Options > Basic > Client secret`)
  427. - JWT Algorithm: RS256 within the security menu of the new Relying Parties
  428. (`Options > Security > ID Token signature algorithm` and `Options > Security >
  429. Access Token signature algorithm`)
  430. - Scopes: OpenID, Email and Profile
  431. - Allowed redirection addresses for login (`Options > Basic > Allowed
  432. redirection addresses for login` ) :
  433. `[synapse public baseurl]/_synapse/client/oidc/callback`
  434. Synapse config:
  435. ```yaml
  436. oidc_providers:
  437. - idp_id: lemonldap
  438. idp_name: lemonldap
  439. discover: true
  440. issuer: "https://auth.example.org/" # TO BE FILLED: replace with your domain
  441. client_id: "your client id" # TO BE FILLED
  442. client_secret: "your client secret" # TO BE FILLED
  443. scopes:
  444. - "openid"
  445. - "profile"
  446. - "email"
  447. user_mapping_provider:
  448. config:
  449. localpart_template: "{{ user.preferred_username }}}"
  450. # 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.
  451. display_name_template: "{{ user.preferred_username|capitalize }}"
  452. ```
  453. ### Mastodon
  454. [Mastodon](https://docs.joinmastodon.org/) instances provide an [OAuth API](https://docs.joinmastodon.org/spec/oauth/), allowing those instances to be used as a single sign-on provider for Synapse.
  455. The first step is to register Synapse as an application with your Mastodon instance, using the [Create an application API](https://docs.joinmastodon.org/methods/apps/#create) (see also [here](https://docs.joinmastodon.org/client/token/)). There are several ways to do this, but in the example below we are using CURL.
  456. This example assumes that:
  457. * the Mastodon instance website URL is `https://your.mastodon.instance.url`, and
  458. * Synapse will be registered as an app named `my_synapse_app`.
  459. Send the following request, substituting the value of `synapse_public_baseurl` from your Synapse installation.
  460. ```sh
  461. 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
  462. ```
  463. You should receive a response similar to the following. Make sure to save it.
  464. ```json
  465. {"client_id":"someclientid_123","client_secret":"someclientsecret_123","id":"12345","name":"my_synapse_app","redirect_uri":"https://[synapse_public_baseurl]/_synapse/client/oidc/callback","website":null,"vapid_key":"somerandomvapidkey_123"}
  466. ```
  467. 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:
  468. ```yaml
  469. oidc_providers:
  470. - idp_id: my_mastodon
  471. idp_name: "Mastodon Instance Example"
  472. discover: false
  473. issuer: "https://your.mastodon.instance.url/@admin"
  474. client_id: "someclientid_123"
  475. client_secret: "someclientsecret_123"
  476. authorization_endpoint: "https://your.mastodon.instance.url/oauth/authorize"
  477. token_endpoint: "https://your.mastodon.instance.url/oauth/token"
  478. userinfo_endpoint: "https://your.mastodon.instance.url/api/v1/accounts/verify_credentials"
  479. scopes: ["read"]
  480. user_mapping_provider:
  481. config:
  482. subject_template: "{{ user.id }}"
  483. localpart_template: "{{ user.username }}"
  484. display_name_template: "{{ user.display_name }}"
  485. ```
  486. Note that the fields `client_id` and `client_secret` are taken from the CURL response above.
  487. ### Shibboleth with OIDC Plugin
  488. [Shibboleth](https://www.shibboleth.net/) is an open Standard IdP solution widely used by Universities.
  489. 1. Shibboleth needs the [OIDC Plugin](https://shibboleth.atlassian.net/wiki/spaces/IDPPLUGINS/pages/1376878976/OIDC+OP) installed and working correctly.
  490. 2. Create a new config on the IdP Side, ensure that the `client_id` and `client_secret`
  491. are randomly generated data.
  492. ```json
  493. {
  494. "client_id": "SOME-CLIENT-ID",
  495. "client_secret": "SOME-SUPER-SECRET-SECRET",
  496. "response_types": ["code"],
  497. "grant_types": ["authorization_code"],
  498. "scope": "openid profile email",
  499. "redirect_uris": ["https://[synapse public baseurl]/_synapse/client/oidc/callback"]
  500. }
  501. ```
  502. Synapse config:
  503. ```yaml
  504. oidc_providers:
  505. # Shibboleth IDP
  506. #
  507. - idp_id: shibboleth
  508. idp_name: "Shibboleth Login"
  509. discover: true
  510. issuer: "https://YOUR-IDP-URL.TLD"
  511. client_id: "YOUR_CLIENT_ID"
  512. client_secret: "YOUR-CLIENT-SECRECT-FROM-YOUR-IDP"
  513. scopes: ["openid", "profile", "email"]
  514. allow_existing_users: true
  515. user_profile_method: "userinfo_endpoint"
  516. user_mapping_provider:
  517. config:
  518. subject_claim: "sub"
  519. localpart_template: "{{ user.sub.split('@')[0] }}"
  520. display_name_template: "{{ user.name }}"
  521. email_template: "{{ user.email }}"
  522. ```
  523. ### Twitch
  524. 1. Setup a developer account on [Twitch](https://dev.twitch.tv/)
  525. 2. Obtain the OAuth 2.0 credentials by [creating an app](https://dev.twitch.tv/console/apps/)
  526. 3. Add this OAuth Redirect URL: `[synapse public baseurl]/_synapse/client/oidc/callback`
  527. Synapse config:
  528. ```yaml
  529. oidc_providers:
  530. - idp_id: twitch
  531. idp_name: Twitch
  532. issuer: "https://id.twitch.tv/oauth2/"
  533. client_id: "your-client-id" # TO BE FILLED
  534. client_secret: "your-client-secret" # TO BE FILLED
  535. client_auth_method: "client_secret_post"
  536. user_mapping_provider:
  537. config:
  538. localpart_template: "{{ user.preferred_username }}"
  539. display_name_template: "{{ user.name }}"
  540. ```
  541. ### Twitter
  542. *Using Twitter as an identity provider requires using Synapse 1.75.0 or later.*
  543. 1. Setup a developer account on [Twitter](https://developer.twitter.com/en/portal/dashboard)
  544. 2. Create a project & app.
  545. 3. Enable user authentication and under "Type of App" choose "Web App, Automated App or Bot".
  546. 4. Under "App info" set the callback URL to `[synapse public baseurl]/_synapse/client/oidc/callback`.
  547. 5. Obtain the OAuth 2.0 credentials under the "Keys and tokens" tab, copy the "OAuth 2.0 Client ID and Client Secret"
  548. Synapse config:
  549. ```yaml
  550. oidc_providers:
  551. - idp_id: twitter
  552. idp_name: Twitter
  553. idp_brand: "twitter" # optional: styling hint for clients
  554. discover: false # Twitter is not OpenID compliant.
  555. issuer: "https://twitter.com/"
  556. client_id: "your-client-id" # TO BE FILLED
  557. client_secret: "your-client-secret" # TO BE FILLED
  558. pkce_method: "always"
  559. # offline.access providers refresh tokens, tweet.read and users.read needed for userinfo request.
  560. scopes: ["offline.access", "tweet.read", "users.read"]
  561. authorization_endpoint: https://twitter.com/i/oauth2/authorize
  562. token_endpoint: https://api.twitter.com/2/oauth2/token
  563. userinfo_endpoint: https://api.twitter.com/2/users/me?user.fields=profile_image_url
  564. user_mapping_provider:
  565. config:
  566. subject_template: "{{ user.data.id }}"
  567. localpart_template: "{{ user.data.username }}"
  568. display_name_template: "{{ user.data.name }}"
  569. picture_template: "{{ user.data.profile_image_url }}"
  570. ```
  571. ### XWiki
  572. Install [OpenID Connect Provider](https://extensions.xwiki.org/xwiki/bin/view/Extension/OpenID%20Connect/OpenID%20Connect%20Provider/) extension in your [XWiki](https://www.xwiki.org) instance.
  573. Synapse config:
  574. ```yaml
  575. oidc_providers:
  576. - idp_id: xwiki
  577. idp_name: "XWiki"
  578. issuer: "https://myxwikihost/xwiki/oidc/"
  579. client_id: "your-client-id" # TO BE FILLED
  580. client_auth_method: none
  581. scopes: ["openid", "profile"]
  582. user_profile_method: "userinfo_endpoint"
  583. user_mapping_provider:
  584. config:
  585. localpart_template: "{{ user.preferred_username }}"
  586. display_name_template: "{{ user.name }}"
  587. ```