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

Implement MSC2290 #6043

Merged
merged 46 commits into from
Sep 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d00435b
Allow HS to send emails when adding an email to the HS
anoadragon453 Sep 16, 2019
c04b2c0
Correct some small issues and fix bug
anoadragon453 Sep 17, 2019
292c007
Address review comments
anoadragon453 Sep 18, 2019
da11cc6
Remove blacklist
anoadragon453 Sep 18, 2019
f5e4c1b
Fix add_threepid template default values in emailconfig
anoadragon453 Sep 18, 2019
bb13515
Re-blacklist tests
anoadragon453 Sep 18, 2019
9718ad6
Factor out removing id_server from msisdn
anoadragon453 Sep 18, 2019
b7cd985
Ensure REMOTE vs LOCAL ThreepidBehaviour is handled
anoadragon453 Sep 19, 2019
1f17307
Move jinja failure template loading into servlet constructor
anoadragon453 Sep 19, 2019
d7ff1cd
Set email
anoadragon453 Sep 19, 2019
7a678a6
Make sure templates only get loaded when necessary
anoadragon453 Sep 19, 2019
102b608
Pull if validation_session out of helper method
anoadragon453 Sep 20, 2019
37281e3
this confused me for so long
anoadragon453 Sep 20, 2019
29fc7bb
Ensure we catch HttpResponseException when calling to id servers
anoadragon453 Sep 20, 2019
f4e93ae
Unpack response from identity server to check for errors
anoadragon453 Sep 20, 2019
b840aff
Factor out password_reset trailing slash change
anoadragon453 Sep 20, 2019
3713c2c
Address review comments
anoadragon453 Sep 20, 2019
8dcb79c
validation_session cannot be None
anoadragon453 Sep 20, 2019
3336902
Just added the endpoints, pulling in infra
anoadragon453 Sep 16, 2019
a7cd54e
Fill out ThreepidAddRestServlet
anoadragon453 Sep 17, 2019
088d6e4
Finish the bind endpoint servlet and remove _extract_items_from_creds…
anoadragon453 Sep 17, 2019
f3fbe5f
Add changelog
anoadragon453 Sep 17, 2019
8463b7d
Make user account deactivation remove bound 3pids not on the user acc…
anoadragon453 Sep 17, 2019
21ea59b
Just added the endpoints, pulling in infra
anoadragon453 Sep 16, 2019
b0a2c2e
Fill out ThreepidAddRestServlet
anoadragon453 Sep 17, 2019
113ebcf
Finish the bind endpoint servlet and remove _extract_items_from_creds…
anoadragon453 Sep 17, 2019
3a0b7f2
Remove id_server from POST /account/3pid/msisdn/requestToken
anoadragon453 Sep 18, 2019
b13db4a
Make sure these new endpoints aren't also on r0
anoadragon453 Sep 19, 2019
4206cfc
Fix wrong config option and delete double servlets
anoadragon453 Sep 20, 2019
8683acc
Correct pulling variables out of validation_session
anoadragon453 Sep 20, 2019
9066368
Make sure to yield
anoadragon453 Sep 20, 2019
c637f74
english
anoadragon453 Sep 20, 2019
d89152d
/account/3pid/add is email only for now
anoadragon453 Sep 20, 2019
4275980
Temporarily c/p /account/3pid to /account/3pid/add
anoadragon453 Sep 20, 2019
c1a676e
Address review comments
anoadragon453 Sep 20, 2019
8fd3581
Consolidate threepid adding functionality in /account/3pid, account/3…
anoadragon453 Sep 20, 2019
66944d7
lint
anoadragon453 Sep 20, 2019
3daf0de
typo
anoadragon453 Sep 20, 2019
e4bb5ab
submit_token got its trailing slash again
anoadragon453 Sep 20, 2019
abc6f20
remove cyclic dep
anoadragon453 Sep 20, 2019
ff9eca5
Forgot my darn yields
anoadragon453 Sep 20, 2019
b61b73a
Re-add error checking on threepid_from_creds
anoadragon453 Sep 20, 2019
4c784e9
address my own review comments
richvdh Sep 23, 2019
93de39b
Update synapse/handlers/identity.py
richvdh Sep 23, 2019
e5f4041
Merge branch 'develop' into anoa/msc2290
richvdh Sep 23, 2019
6b2f8d1
fix bad merge
richvdh Sep 23, 2019
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
30 changes: 26 additions & 4 deletions synapse/handlers/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,16 @@ def threepid_from_creds(self, id_server, creds):

url = id_server + "/_matrix/identity/api/v1/3pid/getValidated3pid"

data = yield self.http_client.get_json(url, query_params)
return data if "medium" in data else None
try:
data = yield self.http_client.get_json(url, query_params)
return data if "medium" in data else None
except HttpResponseException:
logger.debug(
"%s reported non-validated threepid: %s",
self.hs.config.account_threepid_delegate_email,
creds,
)
return None

@defer.inlineCallbacks
def bind_threepid(
Expand Down Expand Up @@ -437,6 +445,10 @@ def validate_threepid_session(self, client_secret, sid):
# XXX: We shouldn't need to keep wrapping and unwrapping this value
threepid_creds = {"client_secret": client_secret, "sid": sid}
Copy link
Member Author

Choose a reason for hiding this comment

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

I'll address this in a future PR


# We don't actually know which medium this 3PID is. Thus we first assume it's email,
# and if validation fails we try msisdn
validation_session = None

# Try to validate as email
if self.hs.config.threepid_behaviour_email == ThreepidBehaviour.REMOTE:
# Ask our delegated email identity server
Expand All @@ -449,7 +461,12 @@ def validate_threepid_session(self, client_secret, sid):
"email", client_secret, sid=sid, validated=True
)

if validation_session:
# Old versions of Sydent return a 200 http code even on a failed validation check.
Copy link
Member

Choose a reason for hiding this comment

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

this comment should be in threepid_from_creds now

# Thus, in addition to the HttpResponseException check above (which checks for
# non-200 errors), we need to make sure validation_session isn't actually an error,
# identified by containing an "error" key
# See https://github.com/matrix-org/sydent/issues/215 for details
if validation_session and "error" not in validation_session:
Copy link
Member

Choose a reason for hiding this comment

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

and afaict the check on error is redundant

return validation_session

# Try to validate as msisdn
Expand All @@ -459,7 +476,12 @@ def validate_threepid_session(self, client_secret, sid):
self.hs.config.account_threepid_delegate_msisdn, threepid_creds
)

return validation_session
# Check that validation_session isn't actually an error due to old Sydent instances
# See explanatory comment above
if validation_session and "error" not in validation_session:
return validation_session

return None


def create_id_access_token_header(id_access_token):
Expand Down
12 changes: 12 additions & 0 deletions synapse/storage/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,18 @@ def add_user_bound_threepid(self, user_id, medium, address, id_server):
)

def user_get_bound_threepids(self, user_id):
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
"""Get the threepids that a user has bound to an identity server through the homeserver
The homeserver remembers where binds to an identity server occurred. Using this
method can retrieve those threepids.

Args:
user_id (str): The ID of the user to retrieve threepids for

Returns:
list[dict(str, str)]: List of dictionaries containing the following:
Copy link
Member

Choose a reason for hiding this comment

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

Deferred

medium (str): The medium of the threepid (e.g "email")
address (str): The address of the threepid (e.g "[email protected]")
"""
return self._simple_select_list(
table="user_threepid_id_server",
keyvalues={"user_id": user_id},
Expand Down