Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 0f3c788

Browse files
committed
move configuration into oidc configuartion
1 parent 7d4d248 commit 0f3c788

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

synapse/handlers/oidc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,7 @@ async def grandfather_existing_users() -> Optional[str]:
12391239
grandfather_existing_users,
12401240
extra_attributes,
12411241
auth_provider_session_id=sid,
1242+
registration_enabled=self._config.enable_registration,
12421243
)
12431244

12441245
def _remote_id_from_userinfo(self, userinfo: UserInfo) -> str:

synapse/handlers/sso.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ def __init__(self, hs: "HomeServer"):
224224

225225
self._consent_at_registration = hs.config.consent.user_consent_at_registration
226226

227-
self._registration_enabled = hs.config.odic.enable_registration
228-
229227
def register_identity_provider(self, p: SsoIdentityProvider) -> None:
230228
p_id = p.idp_id
231229
assert p_id not in self._identity_providers
@@ -385,6 +383,7 @@ async def complete_sso_login_request(
385383
grandfather_existing_users: Callable[[], Awaitable[Optional[str]]],
386384
extra_login_attributes: Optional[JsonDict] = None,
387385
auth_provider_session_id: Optional[str] = None,
386+
registration_enabled: bool = True,
388387
) -> None:
389388
"""
390389
Given an SSO ID, retrieve the user ID for it and possibly register the user.
@@ -437,6 +436,10 @@ async def complete_sso_login_request(
437436
438437
auth_provider_session_id: An optional session ID from the IdP.
439438
439+
registration_enabled: An optional boolean to enable/disable automatic
440+
registrations of new users. If false and the user does not exist then the
441+
flow is aborted. Defaults to true.
442+
440443
Raises:
441444
MappingException if there was a problem mapping the response to a user.
442445
RedirectException: if the mapping provider needs to redirect the user
@@ -464,7 +467,7 @@ async def complete_sso_login_request(
464467
auth_provider_id, remote_user_id, user_id
465468
)
466469

467-
if not user_id and not self._registration_enabled:
470+
if not user_id and not registration_enabled:
468471
logger.info(
469472
"User does not exist and registration are disabled for IdP '%s' and remote_user_id '%s'",
470473
auth_provider_id,

tests/handlers/test_oidc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ def test_extra_attributes(self) -> None:
922922
auth_provider_session_id=None,
923923
)
924924

925-
@override_config({"oidc_config": DEFAULT_CONFIG, "enable_registration": True})
925+
@override_config({"oidc_config": {**DEFAULT_CONFIG, "enable_registration": True}})
926926
def test_map_userinfo_to_user(self) -> None:
927927
"""Ensure that mapping the userinfo returned from a provider to an MXID works properly."""
928928
userinfo: dict = {
@@ -975,7 +975,7 @@ def test_map_userinfo_to_user(self) -> None:
975975
"Mapping provider does not support de-duplicating Matrix IDs",
976976
)
977977

978-
@override_config({"oidc_config": DEFAULT_CONFIG, "enable_registration": False})
978+
@override_config({"oidc_config": {**DEFAULT_CONFIG, "enable_registration": False}})
979979
def test_map_userinfo_to_user_does_not_register_new_user(self) -> None:
980980
"""Ensures new users are not registered if the enabled registration flag is disabled."""
981981
userinfo: dict = {

0 commit comments

Comments
 (0)