openid.html 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. <!DOCTYPE HTML>
  2. <html lang="en" class="sidebar-visible no-js light">
  3. <head>
  4. <!-- Book generated using mdBook -->
  5. <meta charset="UTF-8">
  6. <title>OpenID Connect - Synapse</title>
  7. <!-- Custom HTML head -->
  8. <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  9. <meta name="description" content="">
  10. <meta name="viewport" content="width=device-width, initial-scale=1">
  11. <meta name="theme-color" content="#ffffff" />
  12. <link rel="icon" href="favicon.svg">
  13. <link rel="shortcut icon" href="favicon.png">
  14. <link rel="stylesheet" href="css/variables.css">
  15. <link rel="stylesheet" href="css/general.css">
  16. <link rel="stylesheet" href="css/chrome.css">
  17. <link rel="stylesheet" href="css/print.css" media="print">
  18. <!-- Fonts -->
  19. <link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
  20. <link rel="stylesheet" href="fonts/fonts.css">
  21. <!-- Highlight.js Stylesheets -->
  22. <link rel="stylesheet" href="highlight.css">
  23. <link rel="stylesheet" href="tomorrow-night.css">
  24. <link rel="stylesheet" href="ayu-highlight.css">
  25. <!-- Custom theme stylesheets -->
  26. <link rel="stylesheet" href="docs/website_files/table-of-contents.css">
  27. <link rel="stylesheet" href="docs/website_files/remove-nav-buttons.css">
  28. <link rel="stylesheet" href="docs/website_files/indent-section-headers.css">
  29. <link rel="stylesheet" href="docs/website_files/version-picker.css">
  30. </head>
  31. <body>
  32. <!-- Provide site root to javascript -->
  33. <script type="text/javascript">
  34. var path_to_root = "";
  35. var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
  36. </script>
  37. <!-- Work around some values being stored in localStorage wrapped in quotes -->
  38. <script type="text/javascript">
  39. try {
  40. var theme = localStorage.getItem('mdbook-theme');
  41. var sidebar = localStorage.getItem('mdbook-sidebar');
  42. if (theme.startsWith('"') && theme.endsWith('"')) {
  43. localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
  44. }
  45. if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
  46. localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
  47. }
  48. } catch (e) { }
  49. </script>
  50. <!-- Set the theme before any content is loaded, prevents flash -->
  51. <script type="text/javascript">
  52. var theme;
  53. try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
  54. if (theme === null || theme === undefined) { theme = default_theme; }
  55. var html = document.querySelector('html');
  56. html.classList.remove('no-js')
  57. html.classList.remove('light')
  58. html.classList.add(theme);
  59. html.classList.add('js');
  60. </script>
  61. <!-- Hide / unhide sidebar before it is displayed -->
  62. <script type="text/javascript">
  63. var html = document.querySelector('html');
  64. var sidebar = 'hidden';
  65. if (document.body.clientWidth >= 1080) {
  66. try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
  67. sidebar = sidebar || 'visible';
  68. }
  69. html.classList.remove('sidebar-visible');
  70. html.classList.add("sidebar-" + sidebar);
  71. </script>
  72. <nav id="sidebar" class="sidebar" aria-label="Table of contents">
  73. <div class="sidebar-scrollbox">
  74. <ol class="chapter"><li class="chapter-item expanded affix "><li class="part-title">Introduction</li><li class="chapter-item expanded "><a href="welcome_and_overview.html">Welcome and Overview</a></li><li class="chapter-item expanded affix "><li class="part-title">Setup</li><li class="chapter-item expanded "><a href="setup/installation.html">Installation</a></li><li class="chapter-item expanded "><a href="postgres.html">Using Postgres</a></li><li class="chapter-item expanded "><a href="reverse_proxy.html">Configuring a Reverse Proxy</a></li><li class="chapter-item expanded "><a href="setup/forward_proxy.html">Configuring a Forward/Outbound Proxy</a></li><li class="chapter-item expanded "><a href="turn-howto.html">Configuring a Turn Server</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="setup/turn/coturn.html">coturn TURN server</a></li><li class="chapter-item expanded "><a href="setup/turn/eturnal.html">eturnal TURN server</a></li></ol></li><li class="chapter-item expanded "><a href="delegate.html">Delegation</a></li><li class="chapter-item expanded affix "><li class="part-title">Upgrading</li><li class="chapter-item expanded "><a href="upgrade.html">Upgrading between Synapse Versions</a></li><li class="chapter-item expanded affix "><li class="part-title">Usage</li><li class="chapter-item expanded "><a href="federate.html">Federation</a></li><li class="chapter-item expanded "><a href="usage/configuration/index.html">Configuration</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="usage/configuration/config_documentation.html">Configuration Manual</a></li><li class="chapter-item expanded "><a href="usage/configuration/homeserver_sample_config.html">Homeserver Sample Config File</a></li><li class="chapter-item expanded "><a href="usage/configuration/logging_sample_config.html">Logging Sample Config File</a></li><li class="chapter-item expanded "><a href="structured_logging.html">Structured Logging</a></li><li class="chapter-item expanded "><a href="templates.html">Templates</a></li><li class="chapter-item expanded "><a href="usage/configuration/user_authentication/index.html">User Authentication</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="usage/configuration/user_authentication/single_sign_on/index.html">Single-Sign On</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="openid.html" class="active">OpenID Connect</a></li><li class="chapter-item expanded "><a href="usage/configuration/user_authentication/single_sign_on/saml.html">SAML</a></li><li class="chapter-item expanded "><a href="usage/configuration/user_authentication/single_sign_on/cas.html">CAS</a></li><li class="chapter-item expanded "><a href="sso_mapping_providers.html">SSO Mapping Providers</a></li></ol></li><li class="chapter-item expanded "><a href="password_auth_providers.html">Password Auth Providers</a></li><li class="chapter-item expanded "><a href="jwt.html">JSON Web Tokens</a></li><li class="chapter-item expanded "><a href="usage/configuration/user_authentication/refresh_tokens.html">Refresh Tokens</a></li></ol></li><li class="chapter-item expanded "><a href="CAPTCHA_SETUP.html">Registration Captcha</a></li><li class="chapter-item expanded "><a href="application_services.html">Application Services</a></li><li class="chapter-item expanded "><a href="server_notices.html">Server Notices</a></li><li class="chapter-item expanded "><a href="consent_tracking.html">Consent Tracking</a></li><li class="chapter-item expanded "><a href="user_directory.html">User Directory</a></li><li class="chapter-item expanded "><a href="message_retention_policies.html">Message Retention Policies</a></li><li class="chapter-item expanded "><a href="modules/index.html">Pluggable Modules</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="modules/writing_a_module.html">Writing a module</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="modules/spam_checker_callbacks.html">Spam checker callbacks</a></li><li class="chapter-item expanded "><a href="modules/third_party_rules_callbacks.html">Third-party rules callbacks</a></li><li class="chapter-item expanded "><a href="modules/presence_router_callbacks.html">Presence router callbacks</a></li><li class="chapter-item expanded "><a href="modules/account_validity_callbacks.html">Account validity callbacks</a></li><li class="chapter-item expanded "><a href="modules/password_auth_provider_callbacks.html">Password auth provider callbacks</a></li><li class="chapter-item expanded "><a href="modules/background_update_controller_callbacks.html">Background update controller callbacks</a></li><li class="chapter-item expanded "><a href="modules/account_data_callbacks.html">Account data callbacks</a></li><li class="chapter-item expanded "><a href="modules/porting_legacy_module.html">Porting a legacy module to the new interface</a></li></ol></li></ol></li><li class="chapter-item expanded "><a href="workers.html">Workers</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="synctl_workers.html">Using synctl with Workers</a></li><li class="chapter-item expanded "><a href="systemd-with-workers/index.html">Systemd</a></li></ol></li></ol></li><li class="chapter-item expanded "><a href="usage/administration/index.html">Administration</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="usage/administration/admin_api/index.html">Admin API</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="admin_api/account_validity.html">Account Validity</a></li><li class="chapter-item expanded "><a href="usage/administration/admin_api/background_updates.html">Background Updates</a></li><li class="chapter-item expanded "><a href="admin_api/event_reports.html">Event Reports</a></li><li class="chapter-item expanded "><a href="admin_api/media_admin_api.html">Media</a></li><li class="chapter-item expanded "><a href="admin_api/purge_history_api.html">Purge History</a></li><li class="chapter-item expanded "><a href="admin_api/register_api.html">Register Users</a></li><li class="chapter-item expanded "><a href="usage/administration/admin_api/registration_tokens.html">Registration Tokens</a></li><li class="chapter-item expanded "><a href="admin_api/room_membership.html">Manipulate Room Membership</a></li><li class="chapter-item expanded "><a href="admin_api/rooms.html">Rooms</a></li><li class="chapter-item expanded "><a href="admin_api/server_notices.html">Server Notices</a></li><li class="chapter-item expanded "><a href="admin_api/statistics.html">Statistics</a></li><li class="chapter-item expanded "><a href="admin_api/user_admin_api.html">Users</a></li><li class="chapter-item expanded "><a href="admin_api/version_api.html">Server Version</a></li><li class="chapter-item expanded "><a href="usage/administration/admin_api/federation.html">Federation</a></li></ol></li><li class="chapter-item expanded "><a href="manhole.html">Manhole</a></li><li class="chapter-item expanded "><a href="metrics-howto.html">Monitoring</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="usage/administration/monitoring/reporting_homeserver_usage_statistics.html">Reporting Homeserver Usage Statistics</a></li></ol></li><li class="chapter-item expanded "><a href="usage/administration/monthly_active_users.html">Monthly Active Users</a></li><li class="chapter-item expanded "><a href="usage/administration/understanding_synapse_through_grafana_graphs.html">Understanding Synapse Through Grafana Graphs</a></li><li class="chapter-item expanded "><a href="usage/administration/useful_sql_for_admins.html">Useful SQL for Admins</a></li><li class="chapter-item expanded "><a href="usage/administration/database_maintenance_tools.html">Database Maintenance Tools</a></li><li class="chapter-item expanded "><a href="usage/administration/state_groups.html">State Groups</a></li><li class="chapter-item expanded "><a href="usage/administration/request_log.html">Request log format</a></li><li class="chapter-item expanded "><a href="usage/administration/admin_faq.html">Admin FAQ</a></li><li class="chapter-item expanded "><div>Scripts</div></li></ol></li><li class="chapter-item expanded "><li class="part-title">Development</li><li class="chapter-item expanded "><a href="development/contributing_guide.html">Contributing Guide</a></li><li class="chapter-item expanded "><a href="code_style.html">Code Style</a></li><li class="chapter-item expanded "><a href="development/reviews.html">Reviewing Code</a></li><li class="chapter-item expanded "><a href="development/releases.html">Release Cycle</a></li><li class="chapter-item expanded "><a href="development/git.html">Git Usage</a></li><li class="chapter-item expanded "><div>Testing</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="development/demo.html">Demo scripts</a></li></ol></li><li class="chapter-item expanded "><a href="opentracing.html">OpenTracing</a></li><li class="chapter-item expanded "><a href="development/database_schema.html">Database Schemas</a></li><li class="chapter-item expanded "><a href="development/experimental_features.html">Experimental features</a></li><li class="chapter-item expanded "><a href="development/dependencies.html">Dependency management</a></li><li class="chapter-item expanded "><div>Synapse Architecture</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="development/synapse_architecture/cancellation.html">Cancellation</a></li><li class="chapter-item expanded "><a href="log_contexts.html">Log Contexts</a></li><li class="chapter-item expanded "><a href="replication.html">Replication</a></li><li class="chapter-item expanded "><a href="tcp_replication.html">TCP Replication</a></li><li class="chapter-item expanded "><a href="development/synapse_architecture/faster_joins.html">Faster remote joins</a></li></ol></li><li class="chapter-item expanded "><a href="development/internal_documentation/index.html">Internal Documentation</a></li><li><ol class="section"><li class="chapter-item expanded "><div>Single Sign-On</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="development/saml.html">SAML</a></li><li class="chapter-item expanded "><a href="development/cas.html">CAS</a></li></ol></li><li class="chapter-item expanded "><a href="development/room-dag-concepts.html">Room DAG concepts</a></li><li class="chapter-item expanded "><div>State Resolution</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="auth_chain_difference_algorithm.html">The Auth Chain Difference Algorithm</a></li></ol></li><li class="chapter-item expanded "><a href="media_repository.html">Media Repository</a></li><li class="chapter-item expanded "><a href="room_and_user_statistics.html">Room and User Statistics</a></li></ol></li><li class="chapter-item expanded "><div>Scripts</div></li><li class="chapter-item expanded affix "><li class="part-title">Other</li><li class="chapter-item expanded "><a href="deprecation_policy.html">Dependency Deprecation Policy</a></li><li class="chapter-item expanded "><a href="other/running_synapse_on_single_board_computers.html">Running Synapse on a Single-Board Computer</a></li></ol>
  75. </div>
  76. <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
  77. </nav>
  78. <div id="page-wrapper" class="page-wrapper">
  79. <div class="page">
  80. <div id="menu-bar-hover-placeholder"></div>
  81. <div id="menu-bar" class="menu-bar sticky bordered">
  82. <div class="left-buttons">
  83. <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
  84. <i class="fa fa-bars"></i>
  85. </button>
  86. <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
  87. <i class="fa fa-paint-brush"></i>
  88. </button>
  89. <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
  90. <li role="none"><button role="menuitem" class="theme" id="light">Light (default)</button></li>
  91. <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
  92. <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
  93. <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
  94. <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
  95. </ul>
  96. <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
  97. <i class="fa fa-search"></i>
  98. </button>
  99. <div class="version-picker">
  100. <div class="dropdown">
  101. <div class="select">
  102. <span></span>
  103. <i class="fa fa-chevron-down"></i>
  104. </div>
  105. <input type="hidden" name="version">
  106. <ul class="dropdown-menu">
  107. <!-- Versions will be added dynamically in version-picker.js -->
  108. </ul>
  109. </div>
  110. </div>
  111. </div>
  112. <h1 class="menu-title">Synapse</h1>
  113. <div class="right-buttons">
  114. <a href="print.html" title="Print this book" aria-label="Print this book">
  115. <i id="print-button" class="fa fa-print"></i>
  116. </a>
  117. <a href="https://github.com/matrix-org/synapse" title="Git repository" aria-label="Git repository">
  118. <i id="git-repository-button" class="fa fa-github"></i>
  119. </a>
  120. <a href="https://github.com/matrix-org/synapse/edit/develop/docs/openid.md" title="Suggest an edit" aria-label="Suggest an edit">
  121. <i id="git-edit-button" class="fa fa-edit"></i>
  122. </a>
  123. </div>
  124. </div>
  125. <div id="search-wrapper" class="hidden">
  126. <form id="searchbar-outer" class="searchbar-outer">
  127. <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
  128. </form>
  129. <div id="searchresults-outer" class="searchresults-outer hidden">
  130. <div id="searchresults-header" class="searchresults-header"></div>
  131. <ul id="searchresults">
  132. </ul>
  133. </div>
  134. </div>
  135. <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
  136. <script type="text/javascript">
  137. document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
  138. document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
  139. Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
  140. link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
  141. });
  142. </script>
  143. <div id="content" class="content">
  144. <main>
  145. <!-- Page table of contents -->
  146. <div class="sidetoc">
  147. <nav class="pagetoc"></nav>
  148. </div>
  149. <h1 id="configuring-synapse-to-authenticate-against-an-openid-connect-provider"><a class="header" href="#configuring-synapse-to-authenticate-against-an-openid-connect-provider">Configuring Synapse to authenticate against an OpenID Connect provider</a></h1>
  150. <p>Synapse can be configured to use an OpenID Connect Provider (OP) for
  151. authentication, instead of its own local password database.</p>
  152. <p>Any OP should work with Synapse, as long as it supports the authorization code
  153. flow. There are a few options for that:</p>
  154. <ul>
  155. <li>
  156. <p>start a local OP. Synapse has been tested with <a href="https://www.ory.sh/docs/hydra/">Hydra</a> and
  157. <a href="https://github.com/dexidp/dex">Dex</a>. Note that for an OP to work, it should be served under a
  158. secure (HTTPS) origin. A certificate signed with a self-signed, locally
  159. trusted CA should work. In that case, start Synapse with a <code>SSL_CERT_FILE</code>
  160. environment variable set to the path of the CA.</p>
  161. </li>
  162. <li>
  163. <p>set up a SaaS OP, like <a href="https://developers.google.com/identity/protocols/oauth2/openid-connect">Google</a>, <a href="https://auth0.com/">Auth0</a> or
  164. <a href="https://www.okta.com/">Okta</a>. Synapse has been tested with Auth0 and Google.</p>
  165. </li>
  166. </ul>
  167. <p>It may also be possible to use other OAuth2 providers which provide the
  168. <a href="https://tools.ietf.org/html/rfc6749#section-4.1">authorization code grant type</a>,
  169. such as <a href="https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps">Github</a>.</p>
  170. <h2 id="preparing-synapse"><a class="header" href="#preparing-synapse">Preparing Synapse</a></h2>
  171. <p>The OpenID integration in Synapse uses the
  172. <a href="https://pypi.org/project/Authlib/"><code>authlib</code></a> library, which must be installed
  173. as follows:</p>
  174. <ul>
  175. <li>
  176. <p>The relevant libraries are included in the Docker images and Debian packages
  177. provided by <code>matrix.org</code> so no further action is needed.</p>
  178. </li>
  179. <li>
  180. <p>If you installed Synapse into a virtualenv, run <code>/path/to/env/bin/pip install matrix-synapse[oidc]</code> to install the necessary dependencies.</p>
  181. </li>
  182. <li>
  183. <p>For other installation mechanisms, see the documentation provided by the
  184. maintainer.</p>
  185. </li>
  186. </ul>
  187. <p>To enable the OpenID integration, you should then add a section to the <code>oidc_providers</code>
  188. setting in your configuration file.
  189. See the <a href="usage/configuration/config_documentation.html#oidc_providers">configuration manual</a> for some sample settings, as well as
  190. the text below for example configurations for specific providers.</p>
  191. <h2 id="oidc-back-channel-logout"><a class="header" href="#oidc-back-channel-logout">OIDC Back-Channel Logout</a></h2>
  192. <p>Synapse supports receiving <a href="https://openid.net/specs/openid-connect-backchannel-1_0.html">OpenID Connect Back-Channel Logout</a> notifications.</p>
  193. <p>This lets the OpenID Connect Provider notify Synapse when a user logs out, so that Synapse can end that user session.
  194. This feature can be enabled by setting the <code>backchannel_logout_enabled</code> property to <code>true</code> in the provider configuration, and setting the following URL as destination for Back-Channel Logout notifications in your OpenID Connect Provider: <code>[synapse public baseurl]/_synapse/client/oidc/backchannel_logout</code></p>
  195. <h2 id="sample-configs"><a class="header" href="#sample-configs">Sample configs</a></h2>
  196. <p>Here are a few configs for providers that should work with Synapse.</p>
  197. <h3 id="microsoft-azure-active-directory"><a class="header" href="#microsoft-azure-active-directory">Microsoft Azure Active Directory</a></h3>
  198. <p>Azure AD can act as an OpenID Connect Provider. Register a new application under
  199. <em>App registrations</em> in the Azure AD management console. The RedirectURI for your
  200. application should point to your matrix server:
  201. <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></p>
  202. <p>Go to <em>Certificates &amp; secrets</em> and register a new client secret. Make note of your
  203. Directory (tenant) ID as it will be used in the Azure links.
  204. Edit your Synapse config file and change the <code>oidc_config</code> section:</p>
  205. <pre><code class="language-yaml">oidc_providers:
  206. - idp_id: microsoft
  207. idp_name: Microsoft
  208. issuer: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/v2.0&quot;
  209. client_id: &quot;&lt;client id&gt;&quot;
  210. client_secret: &quot;&lt;client secret&gt;&quot;
  211. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  212. authorization_endpoint: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/oauth2/v2.0/authorize&quot;
  213. token_endpoint: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/oauth2/v2.0/token&quot;
  214. userinfo_endpoint: &quot;https://graph.microsoft.com/oidc/userinfo&quot;
  215. user_mapping_provider:
  216. config:
  217. localpart_template: &quot;{{ user.preferred_username.split('@')[0] }}&quot;
  218. display_name_template: &quot;{{ user.name }}&quot;
  219. </code></pre>
  220. <h3 id="apple"><a class="header" href="#apple">Apple</a></h3>
  221. <p>Configuring &quot;Sign in with Apple&quot; (SiWA) requires an Apple Developer account.</p>
  222. <p>You will need to create a new &quot;Services ID&quot; for SiWA, and create and download a
  223. private key with &quot;SiWA&quot; enabled.</p>
  224. <p>As well as the private key file, you will need:</p>
  225. <ul>
  226. <li>Client ID: the &quot;identifier&quot; you gave the &quot;Services ID&quot;</li>
  227. <li>Team ID: a 10-character ID associated with your developer account.</li>
  228. <li>Key ID: the 10-character identifier for the key.</li>
  229. </ul>
  230. <p><a href="https://help.apple.com/developer-account/?lang=en#/dev77c875b7e">Apple's developer documentation</a>
  231. has more information on setting up SiWA.</p>
  232. <p>The synapse config will look like this:</p>
  233. <pre><code class="language-yaml"> - idp_id: apple
  234. idp_name: Apple
  235. issuer: &quot;https://appleid.apple.com&quot;
  236. client_id: &quot;your-client-id&quot; # Set to the &quot;identifier&quot; for your &quot;ServicesID&quot;
  237. client_auth_method: &quot;client_secret_post&quot;
  238. client_secret_jwt_key:
  239. key_file: &quot;/path/to/AuthKey_KEYIDCODE.p8&quot; # point to your key file
  240. jwt_header:
  241. alg: ES256
  242. kid: &quot;KEYIDCODE&quot; # Set to the 10-char Key ID
  243. jwt_payload:
  244. iss: TEAMIDCODE # Set to the 10-char Team ID
  245. scopes: [&quot;name&quot;, &quot;email&quot;, &quot;openid&quot;]
  246. authorization_endpoint: https://appleid.apple.com/auth/authorize?response_mode=form_post
  247. user_mapping_provider:
  248. config:
  249. email_template: &quot;{{ user.email }}&quot;
  250. </code></pre>
  251. <h3 id="auth0"><a class="header" href="#auth0">Auth0</a></h3>
  252. <p><a href="https://auth0.com/">Auth0</a> is a hosted SaaS IdP solution.</p>
  253. <ol>
  254. <li>
  255. <p>Create a regular web application for Synapse</p>
  256. </li>
  257. <li>
  258. <p>Set the Allowed Callback URLs to <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></p>
  259. </li>
  260. <li>
  261. <p>Add a rule with any name to add the <code>preferred_username</code> claim.
  262. (See https://auth0.com/docs/customize/rules/create-rules for more information on how to create rules.)</p>
  263. <details>
  264. <summary>Code sample</summary>
  265. <pre><code class="language-js">function addPersistenceAttribute(user, context, callback) {
  266. user.user_metadata = user.user_metadata || {};
  267. user.user_metadata.preferred_username = user.user_metadata.preferred_username || user.user_id;
  268. context.idToken.preferred_username = user.user_metadata.preferred_username;
  269. auth0.users.updateUserMetadata(user.user_id, user.user_metadata)
  270. .then(function(){
  271. callback(null, user, context);
  272. })
  273. .catch(function(err){
  274. callback(err);
  275. });
  276. }
  277. </code></pre>
  278. </li>
  279. </ol>
  280. </details>
  281. <p>Synapse config:</p>
  282. <pre><code class="language-yaml">oidc_providers:
  283. - idp_id: auth0
  284. idp_name: Auth0
  285. issuer: &quot;https://your-tier.eu.auth0.com/&quot; # TO BE FILLED
  286. client_id: &quot;your-client-id&quot; # TO BE FILLED
  287. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  288. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  289. user_mapping_provider:
  290. config:
  291. localpart_template: &quot;{{ user.preferred_username }}&quot;
  292. display_name_template: &quot;{{ user.name }}&quot;
  293. </code></pre>
  294. <h3 id="authentik"><a class="header" href="#authentik">Authentik</a></h3>
  295. <p><a href="https://goauthentik.io/">Authentik</a> is an open-source IdP solution.</p>
  296. <ol>
  297. <li>Create a provider in Authentik, with type OAuth2/OpenID.</li>
  298. <li>The parameters are:</li>
  299. </ol>
  300. <ul>
  301. <li>Client Type: Confidential</li>
  302. <li>JWT Algorithm: RS256</li>
  303. <li>Scopes: OpenID, Email and Profile</li>
  304. <li>RSA Key: Select any available key</li>
  305. <li>Redirect URIs: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  306. </ul>
  307. <ol start="3">
  308. <li>Create an application for synapse in Authentik and link it to the provider.</li>
  309. <li>Note the slug of your application, Client ID and Client Secret.</li>
  310. </ol>
  311. <p>Note: RSA keys must be used for signing for Authentik, ECC keys do not work.</p>
  312. <p>Synapse config:</p>
  313. <pre><code class="language-yaml">oidc_providers:
  314. - idp_id: authentik
  315. idp_name: authentik
  316. discover: true
  317. issuer: &quot;https://your.authentik.example.org/application/o/your-app-slug/&quot; # TO BE FILLED: domain and slug
  318. client_id: &quot;your client id&quot; # TO BE FILLED
  319. client_secret: &quot;your client secret&quot; # TO BE FILLED
  320. scopes:
  321. - &quot;openid&quot;
  322. - &quot;profile&quot;
  323. - &quot;email&quot;
  324. user_mapping_provider:
  325. config:
  326. localpart_template: &quot;{{ user.preferred_username }}&quot;
  327. display_name_template: &quot;{{ user.preferred_username|capitalize }}&quot; # TO BE FILLED: If your users have names in Authentik and you want those in Synapse, this should be replaced with user.name|capitalize.
  328. </code></pre>
  329. <h3 id="dex"><a class="header" href="#dex">Dex</a></h3>
  330. <p><a href="https://github.com/dexidp/dex">Dex</a> is a simple, open-source OpenID Connect Provider.
  331. Although it is designed to help building a full-blown provider with an
  332. external database, it can be configured with static passwords in a config file.</p>
  333. <p>Follow the <a href="https://dexidp.io/docs/getting-started/">Getting Started guide</a>
  334. to install Dex.</p>
  335. <p>Edit <code>examples/config-dev.yaml</code> config file from the Dex repo to add a client:</p>
  336. <pre><code class="language-yaml">staticClients:
  337. - id: synapse
  338. secret: secret
  339. redirectURIs:
  340. - '[synapse public baseurl]/_synapse/client/oidc/callback'
  341. name: 'Synapse'
  342. </code></pre>
  343. <p>Run with <code>dex serve examples/config-dev.yaml</code>.</p>
  344. <p>Synapse config:</p>
  345. <pre><code class="language-yaml">oidc_providers:
  346. - idp_id: dex
  347. idp_name: &quot;My Dex server&quot;
  348. skip_verification: true # This is needed as Dex is served on an insecure endpoint
  349. issuer: &quot;http://127.0.0.1:5556/dex&quot;
  350. client_id: &quot;synapse&quot;
  351. client_secret: &quot;secret&quot;
  352. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  353. user_mapping_provider:
  354. config:
  355. localpart_template: &quot;{{ user.name }}&quot;
  356. display_name_template: &quot;{{ user.name|capitalize }}&quot;
  357. </code></pre>
  358. <h3 id="django-oauth-toolkit"><a class="header" href="#django-oauth-toolkit">Django OAuth Toolkit</a></h3>
  359. <p><a href="https://github.com/jazzband/django-oauth-toolkit">django-oauth-toolkit</a> is a
  360. Django application providing out of the box all the endpoints, data and logic
  361. needed to add OAuth2 capabilities to your Django projects. It supports
  362. <a href="https://django-oauth-toolkit.readthedocs.io/en/latest/oidc.html">OpenID Connect too</a>.</p>
  363. <p>Configuration on Django's side:</p>
  364. <ol>
  365. <li>Add an application: <code>https://example.com/admin/oauth2_provider/application/add/</code> and choose parameters like this:</li>
  366. </ol>
  367. <ul>
  368. <li><code>Redirect uris</code>: <code>https://synapse.example.com/_synapse/client/oidc/callback</code></li>
  369. <li><code>Client type</code>: <code>Confidential</code></li>
  370. <li><code>Authorization grant type</code>: <code>Authorization code</code></li>
  371. <li><code>Algorithm</code>: <code>HMAC with SHA-2 256</code></li>
  372. </ul>
  373. <ol start="2">
  374. <li>
  375. <p>You can <a href="https://django-oauth-toolkit.readthedocs.io/en/latest/oidc.html#customizing-the-oidc-responses">customize the claims</a> Django gives to synapse (optional):</p>
  376. <details>
  377. <summary>Code sample</summary>
  378. <pre><code class="language-python">class CustomOAuth2Validator(OAuth2Validator):
  379. def get_additional_claims(self, request):
  380. return {
  381. &quot;sub&quot;: request.user.email,
  382. &quot;email&quot;: request.user.email,
  383. &quot;first_name&quot;: request.user.first_name,
  384. &quot;last_name&quot;: request.user.last_name,
  385. }
  386. </code></pre>
  387. </details>
  388. </li>
  389. </ol>
  390. <p>Your synapse config is then:</p>
  391. <pre><code class="language-yaml">oidc_providers:
  392. - idp_id: django_example
  393. idp_name: &quot;Django Example&quot;
  394. issuer: &quot;https://example.com/o/&quot;
  395. client_id: &quot;your-client-id&quot; # CHANGE ME
  396. client_secret: &quot;your-client-secret&quot; # CHANGE ME
  397. scopes: [&quot;openid&quot;]
  398. user_profile_method: &quot;userinfo_endpoint&quot; # needed because oauth-toolkit does not include user information in the authorization response
  399. user_mapping_provider:
  400. config:
  401. localpart_template: &quot;{{ user.email.split('@')[0] }}&quot;
  402. display_name_template: &quot;{{ user.first_name }} {{ user.last_name }}&quot;
  403. email_template: &quot;{{ user.email }}&quot;
  404. </code></pre>
  405. <h3 id="facebook"><a class="header" href="#facebook">Facebook</a></h3>
  406. <ol start="0">
  407. <li>You will need a Facebook developer account. You can register for one
  408. <a href="https://developers.facebook.com/async/registration/">here</a>.</li>
  409. <li>On the <a href="https://developers.facebook.com/apps/">apps</a> page of the developer
  410. console, &quot;Create App&quot;, and choose &quot;Build Connected Experiences&quot;.</li>
  411. <li>Once the app is created, add &quot;Facebook Login&quot; and choose &quot;Web&quot;. You don't
  412. need to go through the whole form here.</li>
  413. <li>In the left-hand menu, open &quot;Products&quot;/&quot;Facebook Login&quot;/&quot;Settings&quot;.
  414. <ul>
  415. <li>Add <code>[synapse public baseurl]/_synapse/client/oidc/callback</code> as an OAuth Redirect
  416. URL.</li>
  417. </ul>
  418. </li>
  419. <li>In the left-hand menu, open &quot;Settings/Basic&quot;. Here you can copy the &quot;App ID&quot;
  420. and &quot;App Secret&quot; for use below.</li>
  421. </ol>
  422. <p>Synapse config:</p>
  423. <pre><code class="language-yaml"> - idp_id: facebook
  424. idp_name: Facebook
  425. idp_brand: &quot;facebook&quot; # optional: styling hint for clients
  426. discover: false
  427. issuer: &quot;https://www.facebook.com&quot;
  428. client_id: &quot;your-client-id&quot; # TO BE FILLED
  429. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  430. scopes: [&quot;openid&quot;, &quot;email&quot;]
  431. authorization_endpoint: &quot;https://facebook.com/dialog/oauth&quot;
  432. token_endpoint: &quot;https://graph.facebook.com/v9.0/oauth/access_token&quot;
  433. jwks_uri: &quot;https://www.facebook.com/.well-known/oauth/openid/jwks/&quot;
  434. user_mapping_provider:
  435. config:
  436. display_name_template: &quot;{{ user.name }}&quot;
  437. email_template: &quot;{{ user.email }}&quot;
  438. </code></pre>
  439. <p>Relevant documents:</p>
  440. <ul>
  441. <li><a href="https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow">Manually Build a Login Flow</a></li>
  442. <li><a href="https://developers.facebook.com/docs/graph-api/using-graph-api/">Using Facebook's Graph API</a></li>
  443. <li><a href="https://developers.facebook.com/docs/graph-api/reference/user">Reference to the User endpoint</a></li>
  444. </ul>
  445. <p>Facebook do have an <a href="https://www.facebook.com/.well-known/openid-configuration">OIDC discovery endpoint</a>,
  446. but it has a <code>response_types_supported</code> which excludes &quot;code&quot; (which we rely on, and
  447. is even mentioned in their <a href="https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow#login">documentation</a>),
  448. so we have to disable discovery and configure the URIs manually.</p>
  449. <h3 id="github"><a class="header" href="#github">GitHub</a></h3>
  450. <p><a href="https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps">GitHub</a> is a bit special as it is not an OpenID Connect compliant provider, but
  451. just a regular OAuth2 provider.</p>
  452. <p>The <a href="https://developer.github.com/v3/users/#get-the-authenticated-user"><code>/user</code> API endpoint</a>
  453. can be used to retrieve information on the authenticated user. As the Synapse
  454. login mechanism needs an attribute to uniquely identify users, and that endpoint
  455. does not return a <code>sub</code> property, an alternative <code>subject_claim</code> has to be set.</p>
  456. <ol>
  457. <li>Create a new OAuth application: <a href="https://github.com/settings/applications/new">https://github.com/settings/applications/new</a>.</li>
  458. <li>Set the callback URL to <code>[synapse public baseurl]/_synapse/client/oidc/callback</code>.</li>
  459. </ol>
  460. <p>Synapse config:</p>
  461. <pre><code class="language-yaml">oidc_providers:
  462. - idp_id: github
  463. idp_name: Github
  464. idp_brand: &quot;github&quot; # optional: styling hint for clients
  465. discover: false
  466. issuer: &quot;https://github.com/&quot;
  467. client_id: &quot;your-client-id&quot; # TO BE FILLED
  468. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  469. authorization_endpoint: &quot;https://github.com/login/oauth/authorize&quot;
  470. token_endpoint: &quot;https://github.com/login/oauth/access_token&quot;
  471. userinfo_endpoint: &quot;https://api.github.com/user&quot;
  472. scopes: [&quot;read:user&quot;]
  473. user_mapping_provider:
  474. config:
  475. subject_claim: &quot;id&quot;
  476. localpart_template: &quot;{{ user.login }}&quot;
  477. display_name_template: &quot;{{ user.name }}&quot;
  478. </code></pre>
  479. <h3 id="gitlab"><a class="header" href="#gitlab">GitLab</a></h3>
  480. <ol>
  481. <li>Create a <a href="https://gitlab.com/profile/applications">new application</a>.</li>
  482. <li>Add the <code>read_user</code> and <code>openid</code> scopes.</li>
  483. <li>Add this Callback URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  484. </ol>
  485. <p>Synapse config:</p>
  486. <pre><code class="language-yaml">oidc_providers:
  487. - idp_id: gitlab
  488. idp_name: Gitlab
  489. idp_brand: &quot;gitlab&quot; # optional: styling hint for clients
  490. issuer: &quot;https://gitlab.com/&quot;
  491. client_id: &quot;your-client-id&quot; # TO BE FILLED
  492. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  493. client_auth_method: &quot;client_secret_post&quot;
  494. scopes: [&quot;openid&quot;, &quot;read_user&quot;]
  495. user_profile_method: &quot;userinfo_endpoint&quot;
  496. user_mapping_provider:
  497. config:
  498. localpart_template: '{{ user.nickname }}'
  499. display_name_template: '{{ user.name }}'
  500. </code></pre>
  501. <h3 id="gitea"><a class="header" href="#gitea">Gitea</a></h3>
  502. <p>Gitea is, like Github, not an OpenID provider, but just an OAuth2 provider.</p>
  503. <p>The <a href="https://try.gitea.io/api/swagger#/user/userGetCurrent"><code>/user</code> API endpoint</a>
  504. can be used to retrieve information on the authenticated user. As the Synapse
  505. login mechanism needs an attribute to uniquely identify users, and that endpoint
  506. does not return a <code>sub</code> property, an alternative <code>subject_claim</code> has to be set.</p>
  507. <ol>
  508. <li>Create a new application.</li>
  509. <li>Add this Callback URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  510. </ol>
  511. <p>Synapse config:</p>
  512. <pre><code class="language-yaml">oidc_providers:
  513. - idp_id: gitea
  514. idp_name: Gitea
  515. discover: false
  516. issuer: &quot;https://your-gitea.com/&quot;
  517. client_id: &quot;your-client-id&quot; # TO BE FILLED
  518. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  519. client_auth_method: client_secret_post
  520. scopes: [] # Gitea doesn't support Scopes
  521. authorization_endpoint: &quot;https://your-gitea.com/login/oauth/authorize&quot;
  522. token_endpoint: &quot;https://your-gitea.com/login/oauth/access_token&quot;
  523. userinfo_endpoint: &quot;https://your-gitea.com/api/v1/user&quot;
  524. user_mapping_provider:
  525. config:
  526. subject_claim: &quot;id&quot;
  527. localpart_template: &quot;{{ user.login }}&quot;
  528. display_name_template: &quot;{{ user.full_name }}&quot;
  529. </code></pre>
  530. <h3 id="google"><a class="header" href="#google">Google</a></h3>
  531. <p><a href="https://developers.google.com/identity/protocols/oauth2/openid-connect">Google</a> is an OpenID certified authentication and authorisation provider.</p>
  532. <ol>
  533. <li>Set up a project in the Google API Console (see
  534. <a href="https://developers.google.com/identity/protocols/oauth2/openid-connect#appsetup">documentation</a>).</li>
  535. <li>Add an &quot;OAuth Client ID&quot; for a Web Application under &quot;Credentials&quot;.</li>
  536. <li>Copy the Client ID and Client Secret, and add the following to your synapse config:
  537. <pre><code class="language-yaml">oidc_providers:
  538. - idp_id: google
  539. idp_name: Google
  540. idp_brand: &quot;google&quot; # optional: styling hint for clients
  541. issuer: &quot;https://accounts.google.com/&quot;
  542. client_id: &quot;your-client-id&quot; # TO BE FILLED
  543. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  544. scopes: [&quot;openid&quot;, &quot;profile&quot;, &quot;email&quot;] # email is optional, read below
  545. user_mapping_provider:
  546. config:
  547. localpart_template: &quot;{{ user.given_name|lower }}&quot;
  548. display_name_template: &quot;{{ user.name }}&quot;
  549. email_template: &quot;{{ user.email }}&quot; # needs &quot;email&quot; in scopes above
  550. </code></pre>
  551. </li>
  552. <li>Back in the Google console, add this Authorized redirect URI: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code>.</li>
  553. </ol>
  554. <h3 id="keycloak"><a class="header" href="#keycloak">Keycloak</a></h3>
  555. <p><a href="https://www.keycloak.org/docs/latest/server_admin/#sso-protocols">Keycloak</a> is an opensource IdP maintained by Red Hat.</p>
  556. <p>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.
  557. This can be optionally enabled by setting <code>backchannel_logout_enabled</code> to <code>true</code> in the Synapse configuration, and by setting the &quot;Backchannel Logout URL&quot; in Keycloak.</p>
  558. <p>Follow the <a href="https://www.keycloak.org/guides">Getting Started Guide</a> to install Keycloak and set up a realm.</p>
  559. <ol>
  560. <li>
  561. <p>Click <code>Clients</code> in the sidebar and click <code>Create</code></p>
  562. </li>
  563. <li>
  564. <p>Fill in the fields as below:</p>
  565. </li>
  566. </ol>
  567. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  568. <tr><td>Client ID</td><td><code>synapse</code></td></tr>
  569. <tr><td>Client Protocol</td><td><code>openid-connect</code></td></tr>
  570. </tbody></table>
  571. <ol start="3">
  572. <li>Click <code>Save</code></li>
  573. <li>Fill in the fields as below:</li>
  574. </ol>
  575. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  576. <tr><td>Client ID</td><td><code>synapse</code></td></tr>
  577. <tr><td>Enabled</td><td><code>On</code></td></tr>
  578. <tr><td>Client Protocol</td><td><code>openid-connect</code></td></tr>
  579. <tr><td>Access Type</td><td><code>confidential</code></td></tr>
  580. <tr><td>Valid Redirect URIs</td><td><code>[synapse public baseurl]/_synapse/client/oidc/callback</code></td></tr>
  581. <tr><td>Backchannel Logout URL (optional)</td><td> <code>[synapse public baseurl]/_synapse/client/oidc/backchannel_logout</code></td></tr>
  582. <tr><td>Backchannel Logout Session Required (optional)</td><td> <code>On</code></td></tr>
  583. </tbody></table>
  584. <ol start="5">
  585. <li>Click <code>Save</code></li>
  586. <li>On the Credentials tab, update the fields:</li>
  587. </ol>
  588. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  589. <tr><td>Client Authenticator</td><td><code>Client ID and Secret</code></td></tr>
  590. </tbody></table>
  591. <ol start="7">
  592. <li>Click <code>Regenerate Secret</code></li>
  593. <li>Copy Secret</li>
  594. </ol>
  595. <pre><code class="language-yaml">oidc_providers:
  596. - idp_id: keycloak
  597. idp_name: &quot;My KeyCloak server&quot;
  598. issuer: &quot;https://127.0.0.1:8443/realms/{realm_name}&quot;
  599. client_id: &quot;synapse&quot;
  600. client_secret: &quot;copy secret generated from above&quot;
  601. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  602. user_mapping_provider:
  603. config:
  604. localpart_template: &quot;{{ user.preferred_username }}&quot;
  605. display_name_template: &quot;{{ user.name }}&quot;
  606. backchannel_logout_enabled: true # Optional
  607. </code></pre>
  608. <h3 id="lemonldap"><a class="header" href="#lemonldap">LemonLDAP</a></h3>
  609. <p><a href="https://lemonldap-ng.org/">LemonLDAP::NG</a> is an open-source IdP solution.</p>
  610. <ol>
  611. <li>Create an OpenID Connect Relying Parties in LemonLDAP::NG</li>
  612. <li>The parameters are:</li>
  613. </ol>
  614. <ul>
  615. <li>Client ID under the basic menu of the new Relying Parties (<code>Options &gt; Basic &gt; Client ID</code>)</li>
  616. <li>Client secret (<code>Options &gt; Basic &gt; Client secret</code>)</li>
  617. <li>JWT Algorithm: RS256 within the security menu of the new Relying Parties
  618. (<code>Options &gt; Security &gt; ID Token signature algorithm</code> and <code>Options &gt; Security &gt; Access Token signature algorithm</code>)</li>
  619. <li>Scopes: OpenID, Email and Profile</li>
  620. <li>Allowed redirection addresses for login (<code>Options &gt; Basic &gt; Allowed redirection addresses for login</code> ) :
  621. <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  622. </ul>
  623. <p>Synapse config:</p>
  624. <pre><code class="language-yaml">oidc_providers:
  625. - idp_id: lemonldap
  626. idp_name: lemonldap
  627. discover: true
  628. issuer: &quot;https://auth.example.org/&quot; # TO BE FILLED: replace with your domain
  629. client_id: &quot;your client id&quot; # TO BE FILLED
  630. client_secret: &quot;your client secret&quot; # TO BE FILLED
  631. scopes:
  632. - &quot;openid&quot;
  633. - &quot;profile&quot;
  634. - &quot;email&quot;
  635. user_mapping_provider:
  636. config:
  637. localpart_template: &quot;{{ user.preferred_username }}}&quot;
  638. # 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.
  639. display_name_template: &quot;{{ user.preferred_username|capitalize }}&quot;
  640. </code></pre>
  641. <h3 id="mastodon"><a class="header" href="#mastodon">Mastodon</a></h3>
  642. <p><a href="https://docs.joinmastodon.org/">Mastodon</a> instances provide an <a href="https://docs.joinmastodon.org/spec/oauth/">OAuth API</a>, allowing those instances to be used as a single sign-on provider for Synapse.</p>
  643. <p>The first step is to register Synapse as an application with your Mastodon instance, using the <a href="https://docs.joinmastodon.org/methods/apps/#create">Create an application API</a> (see also <a href="https://docs.joinmastodon.org/client/token/">here</a>). There are several ways to do this, but in the example below we are using CURL.</p>
  644. <p>This example assumes that:</p>
  645. <ul>
  646. <li>the Mastodon instance website URL is <code>https://your.mastodon.instance.url</code>, and</li>
  647. <li>Synapse will be registered as an app named <code>my_synapse_app</code>.</li>
  648. </ul>
  649. <p>Send the following request, substituting the value of <code>synapse_public_baseurl</code> from your Synapse installation.</p>
  650. <pre><code class="language-sh">curl -d &quot;client_name=my_synapse_app&amp;redirect_uris=https://[synapse_public_baseurl]/_synapse/client/oidc/callback&quot; -X POST https://your.mastodon.instance.url/api/v1/apps
  651. </code></pre>
  652. <p>You should receive a response similar to the following. Make sure to save it.</p>
  653. <pre><code class="language-json">{&quot;client_id&quot;:&quot;someclientid_123&quot;,&quot;client_secret&quot;:&quot;someclientsecret_123&quot;,&quot;id&quot;:&quot;12345&quot;,&quot;name&quot;:&quot;my_synapse_app&quot;,&quot;redirect_uri&quot;:&quot;https://[synapse_public_baseurl]/_synapse/client/oidc/callback&quot;,&quot;website&quot;:null,&quot;vapid_key&quot;:&quot;somerandomvapidkey_123&quot;}
  654. </code></pre>
  655. <p>As the Synapse login mechanism needs an attribute to uniquely identify users, and Mastodon's endpoint does not return a <code>sub</code> property, an alternative <code>subject_claim</code> has to be set. Your Synapse configuration should include the following:</p>
  656. <pre><code class="language-yaml">oidc_providers:
  657. - idp_id: my_mastodon
  658. idp_name: &quot;Mastodon Instance Example&quot;
  659. discover: false
  660. issuer: &quot;https://your.mastodon.instance.url/@admin&quot;
  661. client_id: &quot;someclientid_123&quot;
  662. client_secret: &quot;someclientsecret_123&quot;
  663. authorization_endpoint: &quot;https://your.mastodon.instance.url/oauth/authorize&quot;
  664. token_endpoint: &quot;https://your.mastodon.instance.url/oauth/token&quot;
  665. userinfo_endpoint: &quot;https://your.mastodon.instance.url/api/v1/accounts/verify_credentials&quot;
  666. scopes: [&quot;read&quot;]
  667. user_mapping_provider:
  668. config:
  669. subject_claim: &quot;id&quot;
  670. </code></pre>
  671. <p>Note that the fields <code>client_id</code> and <code>client_secret</code> are taken from the CURL response above.</p>
  672. <h3 id="shibboleth-with-oidc-plugin"><a class="header" href="#shibboleth-with-oidc-plugin">Shibboleth with OIDC Plugin</a></h3>
  673. <p><a href="https://www.shibboleth.net/">Shibboleth</a> is an open Standard IdP solution widely used by Universities.</p>
  674. <ol>
  675. <li>Shibboleth needs the <a href="https://shibboleth.atlassian.net/wiki/spaces/IDPPLUGINS/pages/1376878976/OIDC+OP">OIDC Plugin</a> installed and working correctly.</li>
  676. <li>Create a new config on the IdP Side, ensure that the <code>client_id</code> and <code>client_secret</code>
  677. are randomly generated data.</li>
  678. </ol>
  679. <pre><code class="language-json">{
  680. &quot;client_id&quot;: &quot;SOME-CLIENT-ID&quot;,
  681. &quot;client_secret&quot;: &quot;SOME-SUPER-SECRET-SECRET&quot;,
  682. &quot;response_types&quot;: [&quot;code&quot;],
  683. &quot;grant_types&quot;: [&quot;authorization_code&quot;],
  684. &quot;scope&quot;: &quot;openid profile email&quot;,
  685. &quot;redirect_uris&quot;: [&quot;https://[synapse public baseurl]/_synapse/client/oidc/callback&quot;]
  686. }
  687. </code></pre>
  688. <p>Synapse config:</p>
  689. <pre><code class="language-yaml">oidc_providers:
  690. # Shibboleth IDP
  691. #
  692. - idp_id: shibboleth
  693. idp_name: &quot;Shibboleth Login&quot;
  694. discover: true
  695. issuer: &quot;https://YOUR-IDP-URL.TLD&quot;
  696. client_id: &quot;YOUR_CLIENT_ID&quot;
  697. client_secret: &quot;YOUR-CLIENT-SECRECT-FROM-YOUR-IDP&quot;
  698. scopes: [&quot;openid&quot;, &quot;profile&quot;, &quot;email&quot;]
  699. allow_existing_users: true
  700. user_profile_method: &quot;userinfo_endpoint&quot;
  701. user_mapping_provider:
  702. config:
  703. subject_claim: &quot;sub&quot;
  704. localpart_template: &quot;{{ user.sub.split('@')[0] }}&quot;
  705. display_name_template: &quot;{{ user.name }}&quot;
  706. email_template: &quot;{{ user.email }}&quot;
  707. </code></pre>
  708. <h3 id="twitch"><a class="header" href="#twitch">Twitch</a></h3>
  709. <ol>
  710. <li>Setup a developer account on <a href="https://dev.twitch.tv/">Twitch</a></li>
  711. <li>Obtain the OAuth 2.0 credentials by <a href="https://dev.twitch.tv/console/apps/">creating an app</a></li>
  712. <li>Add this OAuth Redirect URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  713. </ol>
  714. <p>Synapse config:</p>
  715. <pre><code class="language-yaml">oidc_providers:
  716. - idp_id: twitch
  717. idp_name: Twitch
  718. issuer: &quot;https://id.twitch.tv/oauth2/&quot;
  719. client_id: &quot;your-client-id&quot; # TO BE FILLED
  720. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  721. client_auth_method: &quot;client_secret_post&quot;
  722. user_mapping_provider:
  723. config:
  724. localpart_template: &quot;{{ user.preferred_username }}&quot;
  725. display_name_template: &quot;{{ user.name }}&quot;
  726. </code></pre>
  727. <h3 id="twitter"><a class="header" href="#twitter">Twitter</a></h3>
  728. <p><em>Using Twitter as an identity provider requires using Synapse 1.75.0 or later.</em></p>
  729. <ol>
  730. <li>Setup a developer account on <a href="https://developer.twitter.com/en/portal/dashboard">Twitter</a></li>
  731. <li>Create a project &amp; app.</li>
  732. <li>Enable user authentication and under &quot;Type of App&quot; choose &quot;Web App, Automated App or Bot&quot;.</li>
  733. <li>Under &quot;App info&quot; set the callback URL to <code>[synapse public baseurl]/_synapse/client/oidc/callback</code>.</li>
  734. <li>Obtain the OAuth 2.0 credentials under the &quot;Keys and tokens&quot; tab, copy the &quot;OAuth 2.0 Client ID and Client Secret&quot;</li>
  735. </ol>
  736. <p>Synapse config:</p>
  737. <pre><code class="language-yaml">oidc_providers:
  738. - idp_id: twitter
  739. idp_name: Twitter
  740. idp_brand: &quot;twitter&quot; # optional: styling hint for clients
  741. discover: false # Twitter is not OpenID compliant.
  742. issuer: &quot;https://twitter.com/&quot;
  743. client_id: &quot;your-client-id&quot; # TO BE FILLED
  744. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  745. pkce_method: &quot;always&quot;
  746. # offline.access providers refresh tokens, tweet.read and users.read needed for userinfo request.
  747. scopes: [&quot;offline.access&quot;, &quot;tweet.read&quot;, &quot;users.read&quot;]
  748. authorization_endpoint: https://twitter.com/i/oauth2/authorize
  749. token_endpoint: https://api.twitter.com/2/oauth2/token
  750. userinfo_endpoint: https://api.twitter.com/2/users/me?user.fields=profile_image_url
  751. user_mapping_provider:
  752. config:
  753. subject_template: &quot;{{ user.data.id }}&quot;
  754. localpart_template: &quot;{{ user.data.username }}&quot;
  755. display_name_template: &quot;{{ user.data.name }}&quot;
  756. picture_template: &quot;{{ user.data.profile_image_url }}&quot;
  757. </code></pre>
  758. <h3 id="xwiki"><a class="header" href="#xwiki">XWiki</a></h3>
  759. <p>Install <a href="https://extensions.xwiki.org/xwiki/bin/view/Extension/OpenID%20Connect/OpenID%20Connect%20Provider/">OpenID Connect Provider</a> extension in your <a href="https://www.xwiki.org">XWiki</a> instance.</p>
  760. <p>Synapse config:</p>
  761. <pre><code class="language-yaml">oidc_providers:
  762. - idp_id: xwiki
  763. idp_name: &quot;XWiki&quot;
  764. issuer: &quot;https://myxwikihost/xwiki/oidc/&quot;
  765. client_id: &quot;your-client-id&quot; # TO BE FILLED
  766. client_auth_method: none
  767. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  768. user_profile_method: &quot;userinfo_endpoint&quot;
  769. user_mapping_provider:
  770. config:
  771. localpart_template: &quot;{{ user.preferred_username }}&quot;
  772. display_name_template: &quot;{{ user.name }}&quot;
  773. </code></pre>
  774. </main>
  775. <nav class="nav-wrapper" aria-label="Page navigation">
  776. <!-- Mobile navigation buttons -->
  777. <a rel="prev" href="usage/configuration/user_authentication/single_sign_on/index.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
  778. <i class="fa fa-angle-left"></i>
  779. </a>
  780. <a rel="next" href="usage/configuration/user_authentication/single_sign_on/saml.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
  781. <i class="fa fa-angle-right"></i>
  782. </a>
  783. <div style="clear: both"></div>
  784. </nav>
  785. </div>
  786. </div>
  787. <nav class="nav-wide-wrapper" aria-label="Page navigation">
  788. <a rel="prev" href="usage/configuration/user_authentication/single_sign_on/index.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
  789. <i class="fa fa-angle-left"></i>
  790. </a>
  791. <a rel="next" href="usage/configuration/user_authentication/single_sign_on/saml.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
  792. <i class="fa fa-angle-right"></i>
  793. </a>
  794. </nav>
  795. </div>
  796. <script type="text/javascript">
  797. window.playground_copyable = true;
  798. </script>
  799. <script src="elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
  800. <script src="mark.min.js" type="text/javascript" charset="utf-8"></script>
  801. <script src="searcher.js" type="text/javascript" charset="utf-8"></script>
  802. <script src="clipboard.min.js" type="text/javascript" charset="utf-8"></script>
  803. <script src="highlight.js" type="text/javascript" charset="utf-8"></script>
  804. <script src="book.js" type="text/javascript" charset="utf-8"></script>
  805. <!-- Custom JS scripts -->
  806. <script type="text/javascript" src="docs/website_files/table-of-contents.js"></script>
  807. <script type="text/javascript" src="docs/website_files/version-picker.js"></script>
  808. <script type="text/javascript" src="docs/website_files/version.js"></script>
  809. </body>
  810. </html>