Properly register all callback hooks for legacy password authentication providers (#11340)
Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
This commit is contained in:
parent
24b61f379a
commit
3a1462f7e0
|
@ -0,0 +1 @@
|
||||||
|
Fix a bug, introduced in Synapse 1.46.0, which caused the `check_3pid_auth` and `on_logged_out` callbacks in legacy password authentication provider modules to not be registered. Modules using the generic module API were not affected.
|
|
@ -1828,13 +1828,6 @@ def load_single_legacy_password_auth_provider(
|
||||||
logger.error("Error while initializing %r: %s", module, e)
|
logger.error("Error while initializing %r: %s", module, e)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
# The known hooks. If a module implements a method who's name appears in this set
|
|
||||||
# we'll want to register it
|
|
||||||
password_auth_provider_methods = {
|
|
||||||
"check_3pid_auth",
|
|
||||||
"on_logged_out",
|
|
||||||
}
|
|
||||||
|
|
||||||
# All methods that the module provides should be async, but this wasn't enforced
|
# All methods that the module provides should be async, but this wasn't enforced
|
||||||
# in the old module system, so we wrap them if needed
|
# in the old module system, so we wrap them if needed
|
||||||
def async_wrapper(f: Optional[Callable]) -> Optional[Callable[..., Awaitable]]:
|
def async_wrapper(f: Optional[Callable]) -> Optional[Callable[..., Awaitable]]:
|
||||||
|
@ -1919,11 +1912,14 @@ def load_single_legacy_password_auth_provider(
|
||||||
|
|
||||||
return run
|
return run
|
||||||
|
|
||||||
# populate hooks with the implemented methods, wrapped with async_wrapper
|
# If the module has these methods implemented, then we pull them out
|
||||||
hooks = {
|
# and register them as hooks.
|
||||||
hook: async_wrapper(getattr(provider, hook, None))
|
check_3pid_auth_hook: Optional[CHECK_3PID_AUTH_CALLBACK] = async_wrapper(
|
||||||
for hook in password_auth_provider_methods
|
getattr(provider, "check_3pid_auth", None)
|
||||||
}
|
)
|
||||||
|
on_logged_out_hook: Optional[ON_LOGGED_OUT_CALLBACK] = async_wrapper(
|
||||||
|
getattr(provider, "on_logged_out", None)
|
||||||
|
)
|
||||||
|
|
||||||
supported_login_types = {}
|
supported_login_types = {}
|
||||||
# call get_supported_login_types and add that to the dict
|
# call get_supported_login_types and add that to the dict
|
||||||
|
@ -1950,7 +1946,11 @@ def load_single_legacy_password_auth_provider(
|
||||||
# need to use a tuple here for ("password",) not a list since lists aren't hashable
|
# need to use a tuple here for ("password",) not a list since lists aren't hashable
|
||||||
auth_checkers[(LoginType.PASSWORD, ("password",))] = check_password
|
auth_checkers[(LoginType.PASSWORD, ("password",))] = check_password
|
||||||
|
|
||||||
api.register_password_auth_provider_callbacks(hooks, auth_checkers=auth_checkers)
|
api.register_password_auth_provider_callbacks(
|
||||||
|
check_3pid_auth=check_3pid_auth_hook,
|
||||||
|
on_logged_out=on_logged_out_hook,
|
||||||
|
auth_checkers=auth_checkers,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
CHECK_3PID_AUTH_CALLBACK = Callable[
|
CHECK_3PID_AUTH_CALLBACK = Callable[
|
||||||
|
|
Loading…
Reference in New Issue