openid.html 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  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. </head>
  30. <body>
  31. <!-- Provide site root to javascript -->
  32. <script type="text/javascript">
  33. var path_to_root = "";
  34. var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
  35. </script>
  36. <!-- Work around some values being stored in localStorage wrapped in quotes -->
  37. <script type="text/javascript">
  38. try {
  39. var theme = localStorage.getItem('mdbook-theme');
  40. var sidebar = localStorage.getItem('mdbook-sidebar');
  41. if (theme.startsWith('"') && theme.endsWith('"')) {
  42. localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
  43. }
  44. if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
  45. localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
  46. }
  47. } catch (e) { }
  48. </script>
  49. <!-- Set the theme before any content is loaded, prevents flash -->
  50. <script type="text/javascript">
  51. var theme;
  52. try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
  53. if (theme === null || theme === undefined) { theme = default_theme; }
  54. var html = document.querySelector('html');
  55. html.classList.remove('no-js')
  56. html.classList.remove('light')
  57. html.classList.add(theme);
  58. html.classList.add('js');
  59. </script>
  60. <!-- Hide / unhide sidebar before it is displayed -->
  61. <script type="text/javascript">
  62. var html = document.querySelector('html');
  63. var sidebar = 'hidden';
  64. if (document.body.clientWidth >= 1080) {
  65. try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
  66. sidebar = sidebar || 'visible';
  67. }
  68. html.classList.remove('sidebar-visible');
  69. html.classList.add("sidebar-" + sidebar);
  70. </script>
  71. <nav id="sidebar" class="sidebar" aria-label="Table of contents">
  72. <div class="sidebar-scrollbox">
  73. <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="turn-howto.html">Configuring a Turn Server</a></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 "><a href="MSC1711_certificates_FAQ.html">Upgrading from pre-Synapse 1.0</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/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="usage/configuration/user_authentication/index.html">User Authentication</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="openid.html" class="active">OpenID Connect</a></li><li class="chapter-item expanded "><div>SAML</div></li><li class="chapter-item expanded "><div>CAS</div></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></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="url_previews.html">URL Previews</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.html">Pluggable Modules</a></li><li><ol class="section"><li class="chapter-item expanded "><div>Third Party Rules</div></li><li class="chapter-item expanded "><a href="spam_checker.html">Spam Checker</a></li><li class="chapter-item expanded "><a href="presence_router_module.html">Presence Router</a></li><li class="chapter-item expanded "><div>Media Storage Providers</div></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="admin_api/delete_group.html">Delete Group</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/purge_room.html">Purge Rooms</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="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/shutdown_room.html">Shutdown Room</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></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 class="chapter-item expanded "><a href="usage/administration/request_log.html">Request log format</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="dev/git.html">Git Usage</a></li><li class="chapter-item expanded "><div>Testing</div></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 "><div>Synapse Architecture</div></li><li><ol class="section"><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></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="dev/saml.html">SAML</a></li><li class="chapter-item expanded "><a href="dev/cas.html">CAS</a></li></ol></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></ol>
  74. </div>
  75. <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
  76. </nav>
  77. <div id="page-wrapper" class="page-wrapper">
  78. <div class="page">
  79. <div id="menu-bar-hover-placeholder"></div>
  80. <div id="menu-bar" class="menu-bar sticky bordered">
  81. <div class="left-buttons">
  82. <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
  83. <i class="fa fa-bars"></i>
  84. </button>
  85. <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">
  86. <i class="fa fa-paint-brush"></i>
  87. </button>
  88. <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
  89. <li role="none"><button role="menuitem" class="theme" id="light">Light (default)</button></li>
  90. <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
  91. <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
  92. <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
  93. <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
  94. </ul>
  95. <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">
  96. <i class="fa fa-search"></i>
  97. </button>
  98. </div>
  99. <h1 class="menu-title">Synapse</h1>
  100. <div class="right-buttons">
  101. <a href="print.html" title="Print this book" aria-label="Print this book">
  102. <i id="print-button" class="fa fa-print"></i>
  103. </a>
  104. <a href="https://github.com/matrix-org/synapse" title="Git repository" aria-label="Git repository">
  105. <i id="git-repository-button" class="fa fa-github"></i>
  106. </a>
  107. <a href="https://github.com/matrix-org/synapse/edit/develop/docs/openid.md" title="Suggest an edit" aria-label="Suggest an edit">
  108. <i id="git-edit-button" class="fa fa-edit"></i>
  109. </a>
  110. </div>
  111. </div>
  112. <div id="search-wrapper" class="hidden">
  113. <form id="searchbar-outer" class="searchbar-outer">
  114. <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
  115. </form>
  116. <div id="searchresults-outer" class="searchresults-outer hidden">
  117. <div id="searchresults-header" class="searchresults-header"></div>
  118. <ul id="searchresults">
  119. </ul>
  120. </div>
  121. </div>
  122. <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
  123. <script type="text/javascript">
  124. document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
  125. document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
  126. Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
  127. link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
  128. });
  129. </script>
  130. <div id="content" class="content">
  131. <main>
  132. <!-- Page table of contents -->
  133. <div class="sidetoc">
  134. <nav class="pagetoc"></nav>
  135. </div>
  136. <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>
  137. <p>Synapse can be configured to use an OpenID Connect Provider (OP) for
  138. authentication, instead of its own local password database.</p>
  139. <p>Any OP should work with Synapse, as long as it supports the authorization code
  140. flow. There are a few options for that:</p>
  141. <ul>
  142. <li>
  143. <p>start a local OP. Synapse has been tested with <a href="https://www.ory.sh/docs/hydra/">Hydra</a> and
  144. <a href="https://github.com/dexidp/dex">Dex</a>. Note that for an OP to work, it should be served under a
  145. secure (HTTPS) origin. A certificate signed with a self-signed, locally
  146. trusted CA should work. In that case, start Synapse with a <code>SSL_CERT_FILE</code>
  147. environment variable set to the path of the CA.</p>
  148. </li>
  149. <li>
  150. <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
  151. <a href="https://www.okta.com/">Okta</a>. Synapse has been tested with Auth0 and Google.</p>
  152. </li>
  153. </ul>
  154. <p>It may also be possible to use other OAuth2 providers which provide the
  155. <a href="https://tools.ietf.org/html/rfc6749#section-4.1">authorization code grant type</a>,
  156. such as <a href="https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps">Github</a>.</p>
  157. <h2 id="preparing-synapse"><a class="header" href="#preparing-synapse">Preparing Synapse</a></h2>
  158. <p>The OpenID integration in Synapse uses the
  159. <a href="https://pypi.org/project/Authlib/"><code>authlib</code></a> library, which must be installed
  160. as follows:</p>
  161. <ul>
  162. <li>
  163. <p>The relevant libraries are included in the Docker images and Debian packages
  164. provided by <code>matrix.org</code> so no further action is needed.</p>
  165. </li>
  166. <li>
  167. <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>
  168. </li>
  169. <li>
  170. <p>For other installation mechanisms, see the documentation provided by the
  171. maintainer.</p>
  172. </li>
  173. </ul>
  174. <p>To enable the OpenID integration, you should then add a section to the <code>oidc_providers</code>
  175. setting in your configuration file (or uncomment one of the existing examples).
  176. See <a href="./sample_config.yaml">sample_config.yaml</a> for some sample settings, as well as
  177. the text below for example configurations for specific providers.</p>
  178. <h2 id="sample-configs"><a class="header" href="#sample-configs">Sample configs</a></h2>
  179. <p>Here are a few configs for providers that should work with Synapse.</p>
  180. <h3 id="microsoft-azure-active-directory"><a class="header" href="#microsoft-azure-active-directory">Microsoft Azure Active Directory</a></h3>
  181. <p>Azure AD can act as an OpenID Connect Provider. Register a new application under
  182. <em>App registrations</em> in the Azure AD management console. The RedirectURI for your
  183. application should point to your matrix server:
  184. <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></p>
  185. <p>Go to <em>Certificates &amp; secrets</em> and register a new client secret. Make note of your
  186. Directory (tenant) ID as it will be used in the Azure links.
  187. Edit your Synapse config file and change the <code>oidc_config</code> section:</p>
  188. <pre><code class="language-yaml">oidc_providers:
  189. - idp_id: microsoft
  190. idp_name: Microsoft
  191. issuer: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/v2.0&quot;
  192. client_id: &quot;&lt;client id&gt;&quot;
  193. client_secret: &quot;&lt;client secret&gt;&quot;
  194. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  195. authorization_endpoint: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/oauth2/v2.0/authorize&quot;
  196. token_endpoint: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/oauth2/v2.0/token&quot;
  197. userinfo_endpoint: &quot;https://graph.microsoft.com/oidc/userinfo&quot;
  198. user_mapping_provider:
  199. config:
  200. localpart_template: &quot;{{ user.preferred_username.split('@')[0] }}&quot;
  201. display_name_template: &quot;{{ user.name }}&quot;
  202. </code></pre>
  203. <h3 id="a-hrefhttpsgithubcomdexidpdexdexa"><a class="header" href="#a-hrefhttpsgithubcomdexidpdexdexa"><a href="https://github.com/dexidp/dex">Dex</a></a></h3>
  204. <p><a href="https://github.com/dexidp/dex">Dex</a> is a simple, open-source, certified OpenID Connect Provider.
  205. Although it is designed to help building a full-blown provider with an
  206. external database, it can be configured with static passwords in a config file.</p>
  207. <p>Follow the <a href="https://dexidp.io/docs/getting-started/">Getting Started guide</a>
  208. to install Dex.</p>
  209. <p>Edit <code>examples/config-dev.yaml</code> config file from the Dex repo to add a client:</p>
  210. <pre><code class="language-yaml">staticClients:
  211. - id: synapse
  212. secret: secret
  213. redirectURIs:
  214. - '[synapse public baseurl]/_synapse/client/oidc/callback'
  215. name: 'Synapse'
  216. </code></pre>
  217. <p>Run with <code>dex serve examples/config-dev.yaml</code>.</p>
  218. <p>Synapse config:</p>
  219. <pre><code class="language-yaml">oidc_providers:
  220. - idp_id: dex
  221. idp_name: &quot;My Dex server&quot;
  222. skip_verification: true # This is needed as Dex is served on an insecure endpoint
  223. issuer: &quot;http://127.0.0.1:5556/dex&quot;
  224. client_id: &quot;synapse&quot;
  225. client_secret: &quot;secret&quot;
  226. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  227. user_mapping_provider:
  228. config:
  229. localpart_template: &quot;{{ user.name }}&quot;
  230. display_name_template: &quot;{{ user.name|capitalize }}&quot;
  231. </code></pre>
  232. <h3 id="a-hrefhttpswwwkeycloakorgdocslatestserver_adminsso-protocolskeycloaka"><a class="header" href="#a-hrefhttpswwwkeycloakorgdocslatestserver_adminsso-protocolskeycloaka"><a href="https://www.keycloak.org/docs/latest/server_admin/#sso-protocols">Keycloak</a></a></h3>
  233. <p><a href="https://www.keycloak.org/docs/latest/server_admin/#sso-protocols">Keycloak</a> is an opensource IdP maintained by Red Hat.</p>
  234. <p>Follow the <a href="https://www.keycloak.org/getting-started">Getting Started Guide</a> to install Keycloak and set up a realm.</p>
  235. <ol>
  236. <li>
  237. <p>Click <code>Clients</code> in the sidebar and click <code>Create</code></p>
  238. </li>
  239. <li>
  240. <p>Fill in the fields as below:</p>
  241. </li>
  242. </ol>
  243. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  244. <tr><td>Client ID</td><td><code>synapse</code></td></tr>
  245. <tr><td>Client Protocol</td><td><code>openid-connect</code></td></tr>
  246. </tbody></table>
  247. <ol start="3">
  248. <li>Click <code>Save</code></li>
  249. <li>Fill in the fields as below:</li>
  250. </ol>
  251. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  252. <tr><td>Client ID</td><td><code>synapse</code></td></tr>
  253. <tr><td>Enabled</td><td><code>On</code></td></tr>
  254. <tr><td>Client Protocol</td><td><code>openid-connect</code></td></tr>
  255. <tr><td>Access Type</td><td><code>confidential</code></td></tr>
  256. <tr><td>Valid Redirect URIs</td><td><code>[synapse public baseurl]/_synapse/client/oidc/callback</code></td></tr>
  257. </tbody></table>
  258. <ol start="5">
  259. <li>Click <code>Save</code></li>
  260. <li>On the Credentials tab, update the fields:</li>
  261. </ol>
  262. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  263. <tr><td>Client Authenticator</td><td><code>Client ID and Secret</code></td></tr>
  264. </tbody></table>
  265. <ol start="7">
  266. <li>Click <code>Regenerate Secret</code></li>
  267. <li>Copy Secret</li>
  268. </ol>
  269. <pre><code class="language-yaml">oidc_providers:
  270. - idp_id: keycloak
  271. idp_name: &quot;My KeyCloak server&quot;
  272. issuer: &quot;https://127.0.0.1:8443/auth/realms/{realm_name}&quot;
  273. client_id: &quot;synapse&quot;
  274. client_secret: &quot;copy secret generated from above&quot;
  275. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  276. user_mapping_provider:
  277. config:
  278. localpart_template: &quot;{{ user.preferred_username }}&quot;
  279. display_name_template: &quot;{{ user.name }}&quot;
  280. </code></pre>
  281. <h3 id="a-hrefhttpsauth0comauth0a"><a class="header" href="#a-hrefhttpsauth0comauth0a"><a href="https://auth0.com/">Auth0</a></a></h3>
  282. <ol>
  283. <li>
  284. <p>Create a regular web application for Synapse</p>
  285. </li>
  286. <li>
  287. <p>Set the Allowed Callback URLs to <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></p>
  288. </li>
  289. <li>
  290. <p>Add a rule to add the <code>preferred_username</code> claim.</p>
  291. <details>
  292. <summary>Code sample</summary>
  293. <pre><code class="language-js">function addPersistenceAttribute(user, context, callback) {
  294. user.user_metadata = user.user_metadata || {};
  295. user.user_metadata.preferred_username = user.user_metadata.preferred_username || user.user_id;
  296. context.idToken.preferred_username = user.user_metadata.preferred_username;
  297. auth0.users.updateUserMetadata(user.user_id, user.user_metadata)
  298. .then(function(){
  299. callback(null, user, context);
  300. })
  301. .catch(function(err){
  302. callback(err);
  303. });
  304. }
  305. </code></pre>
  306. </li>
  307. </ol>
  308. </details>
  309. <p>Synapse config:</p>
  310. <pre><code class="language-yaml">oidc_providers:
  311. - idp_id: auth0
  312. idp_name: Auth0
  313. issuer: &quot;https://your-tier.eu.auth0.com/&quot; # TO BE FILLED
  314. client_id: &quot;your-client-id&quot; # TO BE FILLED
  315. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  316. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  317. user_mapping_provider:
  318. config:
  319. localpart_template: &quot;{{ user.preferred_username }}&quot;
  320. display_name_template: &quot;{{ user.name }}&quot;
  321. </code></pre>
  322. <h3 id="github"><a class="header" href="#github">GitHub</a></h3>
  323. <p>GitHub is a bit special as it is not an OpenID Connect compliant provider, but
  324. just a regular OAuth2 provider.</p>
  325. <p>The <a href="https://developer.github.com/v3/users/#get-the-authenticated-user"><code>/user</code> API endpoint</a>
  326. can be used to retrieve information on the authenticated user. As the Synapse
  327. login mechanism needs an attribute to uniquely identify users, and that endpoint
  328. does not return a <code>sub</code> property, an alternative <code>subject_claim</code> has to be set.</p>
  329. <ol>
  330. <li>Create a new OAuth application: https://github.com/settings/applications/new.</li>
  331. <li>Set the callback URL to <code>[synapse public baseurl]/_synapse/client/oidc/callback</code>.</li>
  332. </ol>
  333. <p>Synapse config:</p>
  334. <pre><code class="language-yaml">oidc_providers:
  335. - idp_id: github
  336. idp_name: Github
  337. idp_brand: &quot;github&quot; # optional: styling hint for clients
  338. discover: false
  339. issuer: &quot;https://github.com/&quot;
  340. client_id: &quot;your-client-id&quot; # TO BE FILLED
  341. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  342. authorization_endpoint: &quot;https://github.com/login/oauth/authorize&quot;
  343. token_endpoint: &quot;https://github.com/login/oauth/access_token&quot;
  344. userinfo_endpoint: &quot;https://api.github.com/user&quot;
  345. scopes: [&quot;read:user&quot;]
  346. user_mapping_provider:
  347. config:
  348. subject_claim: &quot;id&quot;
  349. localpart_template: &quot;{{ user.login }}&quot;
  350. display_name_template: &quot;{{ user.name }}&quot;
  351. </code></pre>
  352. <h3 id="a-hrefhttpsdevelopersgooglecomidentityprotocolsoauth2openid-connectgooglea"><a class="header" href="#a-hrefhttpsdevelopersgooglecomidentityprotocolsoauth2openid-connectgooglea"><a href="https://developers.google.com/identity/protocols/oauth2/openid-connect">Google</a></a></h3>
  353. <ol>
  354. <li>Set up a project in the Google API Console (see
  355. https://developers.google.com/identity/protocols/oauth2/openid-connect#appsetup).</li>
  356. <li>add an &quot;OAuth Client ID&quot; for a Web Application under &quot;Credentials&quot;.</li>
  357. <li>Copy the Client ID and Client Secret, and add the following to your synapse config:
  358. <pre><code class="language-yaml">oidc_providers:
  359. - idp_id: google
  360. idp_name: Google
  361. idp_brand: &quot;google&quot; # optional: styling hint for clients
  362. issuer: &quot;https://accounts.google.com/&quot;
  363. client_id: &quot;your-client-id&quot; # TO BE FILLED
  364. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  365. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  366. user_mapping_provider:
  367. config:
  368. localpart_template: &quot;{{ user.given_name|lower }}&quot;
  369. display_name_template: &quot;{{ user.name }}&quot;
  370. </code></pre>
  371. </li>
  372. <li>Back in the Google console, add this Authorized redirect URI: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code>.</li>
  373. </ol>
  374. <h3 id="twitch"><a class="header" href="#twitch">Twitch</a></h3>
  375. <ol>
  376. <li>Setup a developer account on <a href="https://dev.twitch.tv/">Twitch</a></li>
  377. <li>Obtain the OAuth 2.0 credentials by <a href="https://dev.twitch.tv/console/apps/">creating an app</a></li>
  378. <li>Add this OAuth Redirect URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  379. </ol>
  380. <p>Synapse config:</p>
  381. <pre><code class="language-yaml">oidc_providers:
  382. - idp_id: twitch
  383. idp_name: Twitch
  384. issuer: &quot;https://id.twitch.tv/oauth2/&quot;
  385. client_id: &quot;your-client-id&quot; # TO BE FILLED
  386. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  387. client_auth_method: &quot;client_secret_post&quot;
  388. user_mapping_provider:
  389. config:
  390. localpart_template: &quot;{{ user.preferred_username }}&quot;
  391. display_name_template: &quot;{{ user.name }}&quot;
  392. </code></pre>
  393. <h3 id="gitlab"><a class="header" href="#gitlab">GitLab</a></h3>
  394. <ol>
  395. <li>Create a <a href="https://gitlab.com/profile/applications">new application</a>.</li>
  396. <li>Add the <code>read_user</code> and <code>openid</code> scopes.</li>
  397. <li>Add this Callback URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  398. </ol>
  399. <p>Synapse config:</p>
  400. <pre><code class="language-yaml">oidc_providers:
  401. - idp_id: gitlab
  402. idp_name: Gitlab
  403. idp_brand: &quot;gitlab&quot; # optional: styling hint for clients
  404. issuer: &quot;https://gitlab.com/&quot;
  405. client_id: &quot;your-client-id&quot; # TO BE FILLED
  406. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  407. client_auth_method: &quot;client_secret_post&quot;
  408. scopes: [&quot;openid&quot;, &quot;read_user&quot;]
  409. user_profile_method: &quot;userinfo_endpoint&quot;
  410. user_mapping_provider:
  411. config:
  412. localpart_template: '{{ user.nickname }}'
  413. display_name_template: '{{ user.name }}'
  414. </code></pre>
  415. <h3 id="facebook"><a class="header" href="#facebook">Facebook</a></h3>
  416. <p>Like Github, Facebook provide a custom OAuth2 API rather than an OIDC-compliant
  417. one so requires a little more configuration.</p>
  418. <ol start="0">
  419. <li>You will need a Facebook developer account. You can register for one
  420. <a href="https://developers.facebook.com/async/registration/">here</a>.</li>
  421. <li>On the <a href="https://developers.facebook.com/apps/">apps</a> page of the developer
  422. console, &quot;Create App&quot;, and choose &quot;Build Connected Experiences&quot;.</li>
  423. <li>Once the app is created, add &quot;Facebook Login&quot; and choose &quot;Web&quot;. You don't
  424. need to go through the whole form here.</li>
  425. <li>In the left-hand menu, open &quot;Products&quot;/&quot;Facebook Login&quot;/&quot;Settings&quot;.
  426. <ul>
  427. <li>Add <code>[synapse public baseurl]/_synapse/client/oidc/callback</code> as an OAuth Redirect
  428. URL.</li>
  429. </ul>
  430. </li>
  431. <li>In the left-hand menu, open &quot;Settings/Basic&quot;. Here you can copy the &quot;App ID&quot;
  432. and &quot;App Secret&quot; for use below.</li>
  433. </ol>
  434. <p>Synapse config:</p>
  435. <pre><code class="language-yaml"> - idp_id: facebook
  436. idp_name: Facebook
  437. idp_brand: &quot;facebook&quot; # optional: styling hint for clients
  438. discover: false
  439. issuer: &quot;https://facebook.com&quot;
  440. client_id: &quot;your-client-id&quot; # TO BE FILLED
  441. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  442. scopes: [&quot;openid&quot;, &quot;email&quot;]
  443. authorization_endpoint: https://facebook.com/dialog/oauth
  444. token_endpoint: https://graph.facebook.com/v9.0/oauth/access_token
  445. user_profile_method: &quot;userinfo_endpoint&quot;
  446. userinfo_endpoint: &quot;https://graph.facebook.com/v9.0/me?fields=id,name,email,picture&quot;
  447. user_mapping_provider:
  448. config:
  449. subject_claim: &quot;id&quot;
  450. display_name_template: &quot;{{ user.name }}&quot;
  451. </code></pre>
  452. <p>Relevant documents:</p>
  453. <ul>
  454. <li>https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow</li>
  455. <li>Using Facebook's Graph API: https://developers.facebook.com/docs/graph-api/using-graph-api/</li>
  456. <li>Reference to the User endpoint: https://developers.facebook.com/docs/graph-api/reference/user</li>
  457. </ul>
  458. <h3 id="gitea"><a class="header" href="#gitea">Gitea</a></h3>
  459. <p>Gitea is, like Github, not an OpenID provider, but just an OAuth2 provider.</p>
  460. <p>The <a href="https://try.gitea.io/api/swagger#/user/userGetCurrent"><code>/user</code> API endpoint</a>
  461. can be used to retrieve information on the authenticated user. As the Synapse
  462. login mechanism needs an attribute to uniquely identify users, and that endpoint
  463. does not return a <code>sub</code> property, an alternative <code>subject_claim</code> has to be set.</p>
  464. <ol>
  465. <li>Create a new application.</li>
  466. <li>Add this Callback URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  467. </ol>
  468. <p>Synapse config:</p>
  469. <pre><code class="language-yaml">oidc_providers:
  470. - idp_id: gitea
  471. idp_name: Gitea
  472. discover: false
  473. issuer: &quot;https://your-gitea.com/&quot;
  474. client_id: &quot;your-client-id&quot; # TO BE FILLED
  475. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  476. client_auth_method: client_secret_post
  477. scopes: [] # Gitea doesn't support Scopes
  478. authorization_endpoint: &quot;https://your-gitea.com/login/oauth/authorize&quot;
  479. token_endpoint: &quot;https://your-gitea.com/login/oauth/access_token&quot;
  480. userinfo_endpoint: &quot;https://your-gitea.com/api/v1/user&quot;
  481. user_mapping_provider:
  482. config:
  483. subject_claim: &quot;id&quot;
  484. localpart_template: &quot;{{ user.login }}&quot;
  485. display_name_template: &quot;{{ user.full_name }}&quot;
  486. </code></pre>
  487. <h3 id="xwiki"><a class="header" href="#xwiki">XWiki</a></h3>
  488. <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>
  489. <p>Synapse config:</p>
  490. <pre><code class="language-yaml">oidc_providers:
  491. - idp_id: xwiki
  492. idp_name: &quot;XWiki&quot;
  493. issuer: &quot;https://myxwikihost/xwiki/oidc/&quot;
  494. client_id: &quot;your-client-id&quot; # TO BE FILLED
  495. client_auth_method: none
  496. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  497. user_profile_method: &quot;userinfo_endpoint&quot;
  498. user_mapping_provider:
  499. config:
  500. localpart_template: &quot;{{ user.preferred_username }}&quot;
  501. display_name_template: &quot;{{ user.name }}&quot;
  502. </code></pre>
  503. <h2 id="apple"><a class="header" href="#apple">Apple</a></h2>
  504. <p>Configuring &quot;Sign in with Apple&quot; (SiWA) requires an Apple Developer account.</p>
  505. <p>You will need to create a new &quot;Services ID&quot; for SiWA, and create and download a
  506. private key with &quot;SiWA&quot; enabled.</p>
  507. <p>As well as the private key file, you will need:</p>
  508. <ul>
  509. <li>Client ID: the &quot;identifier&quot; you gave the &quot;Services ID&quot;</li>
  510. <li>Team ID: a 10-character ID associated with your developer account.</li>
  511. <li>Key ID: the 10-character identifier for the key.</li>
  512. </ul>
  513. <p>https://help.apple.com/developer-account/?lang=en#/dev77c875b7e has more
  514. documentation on setting up SiWA.</p>
  515. <p>The synapse config will look like this:</p>
  516. <pre><code class="language-yaml"> - idp_id: apple
  517. idp_name: Apple
  518. issuer: &quot;https://appleid.apple.com&quot;
  519. client_id: &quot;your-client-id&quot; # Set to the &quot;identifier&quot; for your &quot;ServicesID&quot;
  520. client_auth_method: &quot;client_secret_post&quot;
  521. client_secret_jwt_key:
  522. key_file: &quot;/path/to/AuthKey_KEYIDCODE.p8&quot; # point to your key file
  523. jwt_header:
  524. alg: ES256
  525. kid: &quot;KEYIDCODE&quot; # Set to the 10-char Key ID
  526. jwt_payload:
  527. iss: TEAMIDCODE # Set to the 10-char Team ID
  528. scopes: [&quot;name&quot;, &quot;email&quot;, &quot;openid&quot;]
  529. authorization_endpoint: https://appleid.apple.com/auth/authorize?response_mode=form_post
  530. user_mapping_provider:
  531. config:
  532. email_template: &quot;{{ user.email }}&quot;
  533. </code></pre>
  534. </main>
  535. <nav class="nav-wrapper" aria-label="Page navigation">
  536. <!-- Mobile navigation buttons -->
  537. <a rel="prev" href="usage/configuration/user_authentication/index.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
  538. <i class="fa fa-angle-left"></i>
  539. </a>
  540. <a rel="next" href="sso_mapping_providers.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
  541. <i class="fa fa-angle-right"></i>
  542. </a>
  543. <div style="clear: both"></div>
  544. </nav>
  545. </div>
  546. </div>
  547. <nav class="nav-wide-wrapper" aria-label="Page navigation">
  548. <a rel="prev" href="usage/configuration/user_authentication/index.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
  549. <i class="fa fa-angle-left"></i>
  550. </a>
  551. <a rel="next" href="sso_mapping_providers.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
  552. <i class="fa fa-angle-right"></i>
  553. </a>
  554. </nav>
  555. </div>
  556. <script type="text/javascript">
  557. window.playground_copyable = true;
  558. </script>
  559. <script src="elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
  560. <script src="mark.min.js" type="text/javascript" charset="utf-8"></script>
  561. <script src="searcher.js" type="text/javascript" charset="utf-8"></script>
  562. <script src="clipboard.min.js" type="text/javascript" charset="utf-8"></script>
  563. <script src="highlight.js" type="text/javascript" charset="utf-8"></script>
  564. <script src="book.js" type="text/javascript" charset="utf-8"></script>
  565. <!-- Custom JS scripts -->
  566. <script type="text/javascript" src="docs/website_files/table-of-contents.js"></script>
  567. </body>
  568. </html>