Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/12526.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add new `registration_token_without_3pids` configuration option to allow registrations via token without needing to verify a 3pid.
10 changes: 10 additions & 0 deletions docs/sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,16 @@ oembed:
#
#registration_requires_token: true

# Allow users to submit a token during registration without requiring them to complete any
# 3pid steps.
# Tokens can be managed using the admin API:
# https://matrix-org.github.io/synapse/latest/usage/administration/admin_api/registration_tokens.html
# Note that `enable_registration` must be set to `true`.
# Disabling this option will not delete any tokens previously generated.
# Defaults to false. Uncomment the following to require tokens:
#
#registration_token_without_3pid: false

# If set, allows registration of standard or admin accounts by anyone who
# has the shared secret, even if registration is otherwise disabled.
#
Expand Down
13 changes: 13 additions & 0 deletions synapse/config/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
self.registration_requires_token = config.get(
"registration_requires_token", False
)
self.registration_token_without_3pids = config.get(
"registration_token_without_3pids", False
)
self.registration_shared_secret = config.get("registration_shared_secret")

self.bcrypt_rounds = config.get("bcrypt_rounds", 12)
Expand Down Expand Up @@ -309,6 +312,16 @@ def generate_config_section(
#
#registration_requires_token: true

# Allow users to submit a token during registration without requiring them to complete any
# 3pid steps.
# Tokens can be managed using the admin API:
# https://matrix-org.github.io/synapse/latest/usage/administration/admin_api/registration_tokens.html
# Note that `enable_registration` must be set to `true`.
# Disabling this option will not delete any tokens previously generated.
# Defaults to false. Uncomment the following to require tokens:
#
#registration_token_without_3pid: false

# If set, allows registration of standard or admin accounts by anyone who
# has the shared secret, even if registration is otherwise disabled.
#
Expand Down
4 changes: 3 additions & 1 deletion synapse/handlers/ui_auth/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ class RegistrationTokenAuthChecker(UserInteractiveAuthChecker):
def __init__(self, hs: "HomeServer"):
super().__init__(hs)
self.hs = hs
self._enabled = bool(hs.config.registration.registration_requires_token)
self._enabled = bool(
hs.config.registration.registration_requires_token
) or bool(hs.config.registration.registration_token_without_3pids)
self.store = hs.get_datastores().main

def is_enabled(self) -> bool:
Expand Down
14 changes: 9 additions & 5 deletions synapse/rest/client/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,15 @@ def _calculate_registration_flows(
# always let users provide both MSISDN & email
flows.append([LoginType.MSISDN, LoginType.EMAIL_IDENTITY])

# Prepend registration token to all flows if we're requiring a token
if config.registration.registration_requires_token:
for flow in flows:
flow.insert(0, LoginType.REGISTRATION_TOKEN)

# Add a flow that doesn't require any 3pids, if the config requests it.
if config.registration.registration_token_without_3pids:
flows.append([LoginType.REGISTRATION_TOKEN])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have been:

flows.append([LoginType.REGISTRATION_TOKEN, LoginType.DUMMY])

...for similar reasons as stated here?


# Prepend m.login.terms to all flows if we're requiring consent
if config.consent.user_consent_at_registration:
for flow in flows:
Expand All @@ -939,11 +948,6 @@ def _calculate_registration_flows(
for flow in flows:
flow.insert(0, LoginType.RECAPTCHA)

# Prepend registration token to all flows if we're requiring a token
if config.registration.registration_requires_token:
for flow in flows:
flow.insert(0, LoginType.REGISTRATION_TOKEN)

return flows


Expand Down