1
0

Compare commits

...

9 Commits

Author SHA1 Message Date
Richard van der Hoff 047b8d7203 Merge remote-tracking branch 'origin/develop' into neilj/fix_check_threepid_for_msisdns 2019-09-25 11:43:32 +01:00
Richard van der Hoff a68ca44dc6 A few more cleanups
Simplify some code, and correct some error messages.
2019-09-25 11:29:10 +01:00
Richard van der Hoff 1ecf6e2286 address ryan's review comment 2019-09-25 11:24:44 +01:00
Richard van der Hoff f8d977f3b7 Merge branch 'rav/refactor_ui_auth' into neilj/fix_check_threepid_for_msisdns 2019-09-25 11:24:22 +01:00
Richard van der Hoff fe2bdc7f55 fix flake8 fails 2019-09-25 10:25:00 +01:00
Neil Johnson bd7e69a095 remove errant print 2019-09-25 09:54:19 +01:00
Neil Johnson c76a0669dd black 2019-09-25 09:54:19 +01:00
Neil Johnson 7e0087449f remove email dependency on msisdn validity checks in _check_threepid 2019-09-25 09:54:19 +01:00
Richard van der Hoff 1f0713b458 Refactor the user-interactive auth handling
Pull the checkers out to their own classes, rather than having them lost in a
massive 1000-line class which does everything.

This is also preparation for some more intelligent advertising of flows, as per
2019-09-25 09:16:50 +01:00
2 changed files with 36 additions and 30 deletions
+1
View File
@@ -0,0 +1 @@
Threepid validity checks on msisdns should not be dependent on 'threepid_behaviour_email'.
+35 -30
View File
@@ -131,42 +131,47 @@ class _BaseThreepidAuthChecker:
identity_handler = self.hs.get_handlers().identity_handler
logger.info("Getting validated threepid. threepidcreds: %r", (threepid_creds,))
if self.hs.config.threepid_behaviour_email == ThreepidBehaviour.REMOTE:
if medium == "email":
# msisdns are currently always ThreepidBehaviour.REMOTE
if medium == "msisdn":
if not self.hs.config.account_threepid_delegate_msisdn:
raise SynapseError(
400, "Phone number verification is not enabled on this homeserver"
)
threepid = yield identity_handler.threepid_from_creds(
self.hs.config.account_threepid_delegate_msisdn, threepid_creds
)
elif medium == "email":
if self.hs.config.threepid_behaviour_email == ThreepidBehaviour.REMOTE:
assert self.hs.config.account_threepid_delegate_email
threepid = yield identity_handler.threepid_from_creds(
self.hs.config.account_threepid_delegate_email, threepid_creds
)
elif medium == "msisdn":
threepid = yield identity_handler.threepid_from_creds(
self.hs.config.account_threepid_delegate_msisdn, threepid_creds
elif self.hs.config.threepid_behaviour_email == ThreepidBehaviour.LOCAL:
threepid = None
row = yield self.store.get_threepid_validation_session(
medium,
threepid_creds["client_secret"],
sid=threepid_creds["sid"],
validated=True,
)
if row:
threepid = {
"medium": row["medium"],
"address": row["address"],
"validated_at": row["validated_at"],
}
# Valid threepid returned, delete from the db
yield self.store.delete_threepid_session(threepid_creds["sid"])
else:
raise SynapseError(400, "Unrecognized threepid medium: %s" % (medium,))
elif self.hs.config.threepid_behaviour_email == ThreepidBehaviour.LOCAL:
row = yield self.store.get_threepid_validation_session(
medium,
threepid_creds["client_secret"],
sid=threepid_creds["sid"],
validated=True,
)
threepid = (
{
"medium": row["medium"],
"address": row["address"],
"validated_at": row["validated_at"],
}
if row
else None
)
if row:
# Valid threepid returned, delete from the db
yield self.store.delete_threepid_session(threepid_creds["sid"])
raise SynapseError(
400, "Email address verification is not enabled on this homeserver"
)
else:
raise SynapseError(
400, "Password resets are not enabled on this homeserver"
)
# this can't happen!
raise AssertionError("Unrecognized threepid medium: %s" % (medium,))
if not threepid:
raise LoginError(401, "", errcode=Codes.UNAUTHORIZED)