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

Commit

Permalink
Merge pull request #4681 from matrix-org/dinsic_anoa/info_split
Browse files Browse the repository at this point in the history
[DINSIC] Use internal-info for identity server
  • Loading branch information
anoadragon453 committed Feb 28, 2019
2 parents dfe09ec + 0a23bf4 commit 3271742
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions synapse/rest/client/v2_alpha/account.py
Expand Up @@ -55,7 +55,7 @@ def on_POST(self, request):
if not (yield check_3pid_allowed(self.hs, "email", body['email'])):
raise SynapseError(
403,
"Your email domain is not authorized on this server",
"Your email is not authorized on this server",
Codes.THREEPID_DENIED,
)

Expand Down Expand Up @@ -271,7 +271,7 @@ def on_POST(self, request):
if not (yield check_3pid_allowed(self.hs, "email", body['email'])):
raise SynapseError(
403,
"Your email domain is not authorized on this server",
"Your email is not authorized on this server",
Codes.THREEPID_DENIED,
)

Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/client/v2_alpha/register.py
Expand Up @@ -78,7 +78,7 @@ def on_POST(self, request):
if not (yield check_3pid_allowed(self.hs, "email", body['email'])):
raise SynapseError(
403,
"Your email domain is not authorized to register on this server",
"Your email is not authorized to register on this server",
Codes.THREEPID_DENIED,
)

Expand Down
22 changes: 16 additions & 6 deletions synapse/util/threepids.py
Expand Up @@ -23,7 +23,7 @@

@defer.inlineCallbacks
def check_3pid_allowed(hs, medium, address):
"""Checks whether a given format of 3PID is allowed to be used on this HS
"""Checks whether a given 3PID is allowed to be used on this HS
Args:
hs (synapse.server.HomeServer): server
Expand All @@ -38,14 +38,24 @@ def check_3pid_allowed(hs, medium, address):
data = yield hs.get_simple_http_client().get_json(
"https://%s%s" % (
hs.config.check_is_for_allowed_local_3pids,
"/_matrix/identity/api/v1/info"
"/_matrix/identity/api/v1/internal-info"
),
{'medium': medium, 'address': address}
)
if hs.config.allow_invited_3pids and data.get('invited'):
defer.returnValue(True)
else:
defer.returnValue(data['hs'] == hs.config.server_name)

# Check for invalid response
if 'hs' not in data and 'shadow_hs' not in data:
defer.returnValue(False)

# Check if this user is intended to register for this homeserver
if data['hs'] != hs.config.server_name and data['shadow_hs'] != hs.config.server_name:
defer.returnValue(False)

if data.get('requires_invite', False) and not data.get('invited', False):
# Requires an invite but hasn't been invited
defer.returnValue(False)

defer.returnValue(True)

if hs.config.allowed_local_3pids:
for constraint in hs.config.allowed_local_3pids:
Expand Down

0 comments on commit 3271742

Please sign in to comment.