@@ -282,6 +282,101 @@ the request is a server admin.
282282Modules can modify the `request_content` (by e.g. adding events to its `initial_state`),
283283or deny the room's creation by raising a `module_api.errors.SynapseError`.
284284
285+ # ### Password auth provider callbacks
286+
287+ Password auth providers offer a way for server administrators to integrate
288+ their Synapse installation with an existing authentication system. The callbacks can be
289+ registered by using the Module API's `register_password_auth_provider_callbacks` method.
290+
291+ To register authentication checkers, the module should register both of :
292+
293+ - `supported_login_types : Dict[str, Iterable[str]]`
294+
295+ A dict mapping from a login type identifier (such as `m.login.password`) to an
296+ iterable giving the fields which must be provided by the user in the submission
297+ to the `/login` API.
298+
299+ For example, if a module wants to implement a custom login type of
300+ ` com.example.custom_login` , where the client is expected to pass the fields `secret1`
301+ and `secret2` and an alternative password authenticator for `m.login.password`, then
302+ it should register the following dict :
303+
304+ ` ` ` python
305+ {
306+ "com.example.custom_login": ("secret1", "secret2"),
307+ "m.login.password": ("password",)
308+ }
309+ ` ` `
310+
311+ - `auth_checkers : Dict[str, CHECK_AUTH]`
312+
313+ A dict mapping from a login type identifier (such as `m.login.password`) to an authentication
314+ checking method of the following form :
315+
316+ ` ` ` python
317+ async def check_auth(
318+ username: str,
319+ login_type: str,
320+ login_dict: JsonDict
321+ ) -> Optional[Union[str, Tuple[str, Optional[Callable]]]]
322+ ` ` `
323+
324+ It is passed the (possibly unqualified) user field provided by the client,
325+ the login type, and a dictionary of login secrets passed by the client.
326+
327+ If authentication was successful, then it should return either a str containing
328+ the user's (canonical) User id or a (user_id, callback) tuple, where the callback is
329+ called with the result from the `/login` call (see the
330+ <a href="https://spec.matrix.org/unstable/client-server-api/#login">spec</a>
331+ for details).
332+
333+ So continuing the same example, if the module has two authentication checkers, one for
334+ ` com.example.custom_login` called `self.custom_check` and one for `m.login.password` called
335+ `self.password_check` then it should register the following dict :
336+
337+ ` ` ` python
338+ {
339+ "com.example.custom_login": self.custom_check,
340+ "m.login.password": self.password_check,
341+ }
342+ ` ` `
343+
344+ Additionally, the following callbacks are available :
345+
346+ ` ` ` python
347+ async def check_3pid_auth(
348+ medium: str,
349+ address: str,
350+ password: str,
351+ ) -> Optional[Union[str, Tuple[str, Optional[Callable]]]]
352+ ` ` `
353+
354+ This is called when a user attempts to register or log in with a third party identifier,
355+ such as email. It is passed the medium (eg. "email"), an address (eg. "jdoe@example.com")
356+ and the user's password.
357+
358+ The method should return None if the authentication is unsuccessful.
359+
360+ If authentication was successful, then it should return either a str containing
361+ the user's (canonical) User id or a (user_id, callback) tuple, where the callback is
362+ called with the result from the `/login` call (see the
363+ <a href="https://spec.matrix.org/unstable/client-server-api/#login">spec</a>
364+ for details).
365+
366+ ` ` ` python
367+ async def on_logged_out(
368+ user_id: str,
369+ device_id: str,
370+ access_token: str,
371+ ) -> None
372+ ` ` `
373+ This is called when a user logs out. It is passed the qualified user ID, the ID of the
374+ deactivated device (if any : access tokens are occasionally created without an associated
375+ device ID), and the (now deactivated) access token.
376+
377+ The callback must be asynchronous but the logout request will wait for the callback
378+ to complete.
379+
285380
286381# ## Porting an existing module that uses the old interface
287382
0 commit comments