|
@@ -32,12 +32,14 @@ from synapse.api.errors import (
|
|
ThreepidValidationError,
|
|
ThreepidValidationError,
|
|
UnrecognizedRequestError,
|
|
UnrecognizedRequestError,
|
|
)
|
|
)
|
|
|
|
+from synapse.config import ConfigError
|
|
from synapse.config.captcha import CaptchaConfig
|
|
from synapse.config.captcha import CaptchaConfig
|
|
from synapse.config.consent_config import ConsentConfig
|
|
from synapse.config.consent_config import ConsentConfig
|
|
from synapse.config.emailconfig import ThreepidBehaviour
|
|
from synapse.config.emailconfig import ThreepidBehaviour
|
|
from synapse.config.ratelimiting import FederationRateLimitConfig
|
|
from synapse.config.ratelimiting import FederationRateLimitConfig
|
|
from synapse.config.registration import RegistrationConfig
|
|
from synapse.config.registration import RegistrationConfig
|
|
from synapse.config.server import is_threepid_reserved
|
|
from synapse.config.server import is_threepid_reserved
|
|
|
|
+from synapse.handlers.auth import AuthHandler
|
|
from synapse.http.server import finish_request
|
|
from synapse.http.server import finish_request
|
|
from synapse.http.servlet import (
|
|
from synapse.http.servlet import (
|
|
RestServlet,
|
|
RestServlet,
|
|
@@ -375,7 +377,9 @@ class RegisterRestServlet(RestServlet):
|
|
self.ratelimiter = hs.get_registration_ratelimiter()
|
|
self.ratelimiter = hs.get_registration_ratelimiter()
|
|
self.clock = hs.get_clock()
|
|
self.clock = hs.get_clock()
|
|
|
|
|
|
- self._registration_flows = _calculate_registration_flows(hs.config)
|
|
|
|
|
|
+ self._registration_flows = _calculate_registration_flows(
|
|
|
|
+ hs.config, self.auth_handler
|
|
|
|
+ )
|
|
|
|
|
|
@interactive_auth_handler
|
|
@interactive_auth_handler
|
|
@defer.inlineCallbacks
|
|
@defer.inlineCallbacks
|
|
@@ -664,11 +668,13 @@ class RegisterRestServlet(RestServlet):
|
|
def _calculate_registration_flows(
|
|
def _calculate_registration_flows(
|
|
# technically `config` has to provide *all* of these interfaces, not just one
|
|
# technically `config` has to provide *all* of these interfaces, not just one
|
|
config: Union[RegistrationConfig, ConsentConfig, CaptchaConfig],
|
|
config: Union[RegistrationConfig, ConsentConfig, CaptchaConfig],
|
|
|
|
+ auth_handler: AuthHandler,
|
|
) -> List[List[str]]:
|
|
) -> List[List[str]]:
|
|
"""Get a suitable flows list for registration
|
|
"""Get a suitable flows list for registration
|
|
|
|
|
|
Args:
|
|
Args:
|
|
config: server configuration
|
|
config: server configuration
|
|
|
|
+ auth_handler: authorization handler
|
|
|
|
|
|
Returns: a list of supported flows
|
|
Returns: a list of supported flows
|
|
"""
|
|
"""
|
|
@@ -678,10 +684,29 @@ def _calculate_registration_flows(
|
|
require_msisdn = "msisdn" in config.registrations_require_3pid
|
|
require_msisdn = "msisdn" in config.registrations_require_3pid
|
|
|
|
|
|
show_msisdn = True
|
|
show_msisdn = True
|
|
|
|
+ show_email = True
|
|
|
|
+
|
|
if config.disable_msisdn_registration:
|
|
if config.disable_msisdn_registration:
|
|
show_msisdn = False
|
|
show_msisdn = False
|
|
require_msisdn = False
|
|
require_msisdn = False
|
|
|
|
|
|
|
|
+ enabled_auth_types = auth_handler.get_enabled_auth_types()
|
|
|
|
+ if LoginType.EMAIL_IDENTITY not in enabled_auth_types:
|
|
|
|
+ show_email = False
|
|
|
|
+ if require_email:
|
|
|
|
+ raise ConfigError(
|
|
|
|
+ "Configuration requires email address at registration, but email "
|
|
|
|
+ "validation is not configured"
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ if LoginType.MSISDN not in enabled_auth_types:
|
|
|
|
+ show_msisdn = False
|
|
|
|
+ if require_msisdn:
|
|
|
|
+ raise ConfigError(
|
|
|
|
+ "Configuration requires msisdn at registration, but msisdn "
|
|
|
|
+ "validation is not configured"
|
|
|
|
+ )
|
|
|
|
+
|
|
flows = []
|
|
flows = []
|
|
|
|
|
|
# only support 3PIDless registration if no 3PIDs are required
|
|
# only support 3PIDless registration if no 3PIDs are required
|
|
@@ -693,14 +718,15 @@ def _calculate_registration_flows(
|
|
flows.append([LoginType.DUMMY])
|
|
flows.append([LoginType.DUMMY])
|
|
|
|
|
|
# only support the email-only flow if we don't require MSISDN 3PIDs
|
|
# only support the email-only flow if we don't require MSISDN 3PIDs
|
|
- if not require_msisdn:
|
|
|
|
|
|
+ if show_email and not require_msisdn:
|
|
flows.append([LoginType.EMAIL_IDENTITY])
|
|
flows.append([LoginType.EMAIL_IDENTITY])
|
|
|
|
|
|
# only support the MSISDN-only flow if we don't require email 3PIDs
|
|
# only support the MSISDN-only flow if we don't require email 3PIDs
|
|
if show_msisdn and not require_email:
|
|
if show_msisdn and not require_email:
|
|
flows.append([LoginType.MSISDN])
|
|
flows.append([LoginType.MSISDN])
|
|
|
|
|
|
- if show_msisdn:
|
|
|
|
|
|
+ if show_email and show_msisdn:
|
|
|
|
+ # always let users provide both MSISDN & email
|
|
flows.append([LoginType.MSISDN, LoginType.EMAIL_IDENTITY])
|
|
flows.append([LoginType.MSISDN, LoginType.EMAIL_IDENTITY])
|
|
|
|
|
|
# Prepend m.login.terms to all flows if we're requiring consent
|
|
# Prepend m.login.terms to all flows if we're requiring consent
|