def _calculate_registration_flows( config: HomeServerConfig, auth_handler: AuthHandler) -> List[List[str]]: """Get a suitable flows list for registration Args: config: server configuration auth_handler: authorization handler Returns: a list of supported flows """ # FIXME: need a better error than "no auth flow found" for scenarios # where we required 3PID for registration but the user didn't give one require_email = "email" in config.registration.registrations_require_3pid require_msisdn = "msisdn" in config.registration.registrations_require_3pid show_msisdn = True show_email = True if config.registration.disable_msisdn_registration: show_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 = [] # only support 3PIDless registration if no 3PIDs are required if not require_email and not require_msisdn: # Add a dummy step here, otherwise if a client completes # recaptcha first we'll assume they were going for this flow # and complete the request, when they could have been trying to # complete one of the flows with email/msisdn auth. flows.append([LoginType.DUMMY]) # only support the email-only flow if we don't require MSISDN 3PIDs if show_email and not require_msisdn: flows.append([LoginType.EMAIL_IDENTITY]) # only support the MSISDN-only flow if we don't require email 3PIDs if show_msisdn and not require_email: flows.append([LoginType.MSISDN]) if show_email and show_msisdn: # always let users provide both MSISDN & email flows.append([LoginType.MSISDN, LoginType.EMAIL_IDENTITY]) # Prepend m.login.terms to all flows if we're requiring consent if config.consent.user_consent_at_registration: for flow in flows: flow.insert(0, LoginType.TERMS) # Prepend recaptcha to all flows if we're requiring captcha if config.captcha.enable_registration_captcha: 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
def get_auth_handler(self) -> AuthHandler: return AuthHandler(self)
def build_auth_handler(self): return AuthHandler(self)
def __init__(self, hs): self.auth_handler = AuthHandler(hs)