Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

password_auth_providers.md 5.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <h2 style="color:red">
  2. This page of the Synapse documentation is now deprecated. For up to date
  3. documentation on setting up or writing a password auth provider module, please see
  4. <a href="modules/index.md">this page</a>.
  5. </h2>
  6. # Password auth provider modules
  7. Password auth providers offer a way for server administrators to
  8. integrate their Synapse installation with an existing authentication
  9. system.
  10. A password auth provider is a Python class which is dynamically loaded
  11. into Synapse, and provides a number of methods by which it can integrate
  12. with the authentication system.
  13. This document serves as a reference for those looking to implement their
  14. own password auth providers. Additionally, here is a list of known
  15. password auth provider module implementations:
  16. * [matrix-synapse-ldap3](https://github.com/matrix-org/matrix-synapse-ldap3/)
  17. * [matrix-synapse-shared-secret-auth](https://github.com/devture/matrix-synapse-shared-secret-auth)
  18. * [matrix-synapse-rest-password-provider](https://github.com/ma1uta/matrix-synapse-rest-password-provider)
  19. ## Required methods
  20. Password auth provider classes must provide the following methods:
  21. * `parse_config(config)`
  22. This method is passed the `config` object for this module from the
  23. homeserver configuration file.
  24. It should perform any appropriate sanity checks on the provided
  25. configuration, and return an object which is then passed into
  26. `__init__`.
  27. This method should have the `@staticmethod` decoration.
  28. * `__init__(self, config, account_handler)`
  29. The constructor is passed the config object returned by
  30. `parse_config`, and a `synapse.module_api.ModuleApi` object which
  31. allows the password provider to check if accounts exist and/or create
  32. new ones.
  33. ## Optional methods
  34. Password auth provider classes may optionally provide the following methods:
  35. * `get_db_schema_files(self)`
  36. This method, if implemented, should return an Iterable of
  37. `(name, stream)` pairs of database schema files. Each file is applied
  38. in turn at initialisation, and a record is then made in the database
  39. so that it is not re-applied on the next start.
  40. * `get_supported_login_types(self)`
  41. This method, if implemented, should return a `dict` mapping from a
  42. login type identifier (such as `m.login.password`) to an iterable
  43. giving the fields which must be provided by the user in the submission
  44. to [the `/login` API](https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-login).
  45. These fields are passed in the `login_dict` dictionary to `check_auth`.
  46. For example, if a password auth provider wants to implement a custom
  47. login type of `com.example.custom_login`, where the client is expected
  48. to pass the fields `secret1` and `secret2`, the provider should
  49. implement this method and return the following dict:
  50. ```python
  51. {"com.example.custom_login": ("secret1", "secret2")}
  52. ```
  53. * `check_auth(self, username, login_type, login_dict)`
  54. This method does the real work. If implemented, it
  55. will be called for each login attempt where the login type matches one
  56. of the keys returned by `get_supported_login_types`.
  57. It is passed the (possibly unqualified) `user` field provided by the client,
  58. the login type, and a dictionary of login secrets passed by the
  59. client.
  60. The method should return an `Awaitable` object, which resolves
  61. to the canonical `@localpart:domain` user ID if authentication is
  62. successful, and `None` if not.
  63. Alternatively, the `Awaitable` can resolve to a `(str, func)` tuple, in
  64. which case the second field is a callback which will be called with
  65. the result from the `/login` call (including `access_token`,
  66. `device_id`, etc.)
  67. * `check_3pid_auth(self, medium, address, password)`
  68. This method, if implemented, is called when a user attempts to
  69. register or log in with a third party identifier, such as email. It is
  70. passed the medium (ex. "email"), an address (ex.
  71. "<jdoe@example.com>") and the user's password.
  72. The method should return an `Awaitable` object, which resolves
  73. to a `str` containing the user's (canonical) User id if
  74. authentication was successful, and `None` if not.
  75. As with `check_auth`, the `Awaitable` may alternatively resolve to a
  76. `(user_id, callback)` tuple.
  77. * `check_password(self, user_id, password)`
  78. This method provides a simpler interface than
  79. `get_supported_login_types` and `check_auth` for password auth
  80. providers that just want to provide a mechanism for validating
  81. `m.login.password` logins.
  82. If implemented, it will be called to check logins with an
  83. `m.login.password` login type. It is passed a qualified
  84. `@localpart:domain` user id, and the password provided by the user.
  85. The method should return an `Awaitable` object, which resolves
  86. to `True` if authentication is successful, and `False` if not.
  87. * `on_logged_out(self, user_id, device_id, access_token)`
  88. This method, if implemented, is called when a user logs out. It is
  89. passed the qualified user ID, the ID of the deactivated device (if
  90. any: access tokens are occasionally created without an associated
  91. device ID), and the (now deactivated) access token.
  92. It may return an `Awaitable` object; the logout request will
  93. wait for the `Awaitable` to complete, but the result is ignored.