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

Return well_known in /login response #4319

Merged
merged 3 commits into from
Dec 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions changelog.d/4319.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Return server data in /login response
18 changes: 11 additions & 7 deletions synapse/rest/client/v1/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
parse_json_object_from_request,
parse_string,
)
from synapse.rest.well_known import WellKnownBuilder
from synapse.types import UserID, map_username_to_mxid_localpart
from synapse.util.msisdn import phone_number_to_msisdn

Expand Down Expand Up @@ -95,6 +96,7 @@ def __init__(self, hs):
self.auth_handler = self.hs.get_auth_handler()
self.device_handler = self.hs.get_device_handler()
self.handlers = hs.get_handlers()
self._well_known_builder = WellKnownBuilder(hs)

def on_GET(self, request):
flows = []
Expand Down Expand Up @@ -132,16 +134,18 @@ def on_POST(self, request):
if self.jwt_enabled and (login_submission["type"] ==
LoginRestServlet.JWT_TYPE):
result = yield self.do_jwt_login(login_submission)
defer.returnValue(result)
elif login_submission["type"] == LoginRestServlet.TOKEN_TYPE:
result = yield self.do_token_login(login_submission)
defer.returnValue(result)
else:
result = yield self._do_other_login(login_submission)
defer.returnValue(result)
except KeyError:
raise SynapseError(400, "Missing JSON keys.")

well_known_data = self._well_known_builder.get_well_known()
if well_known_data:
result["well_known"] = well_known_data
defer.returnValue((200, result))

@defer.inlineCallbacks
def _do_other_login(self, login_submission):
"""Handle non-token/saml/jwt logins
Expand All @@ -150,7 +154,7 @@ def _do_other_login(self, login_submission):
login_submission:

Returns:
(int, object): HTTP code/response
dict: HTTP response
"""
# Log the request we got, but only certain fields to minimise the chance of
# logging someone's password (even if they accidentally put it in the wrong
Expand Down Expand Up @@ -233,7 +237,7 @@ def _do_other_login(self, login_submission):
if callback is not None:
yield callback(result)

defer.returnValue((200, result))
defer.returnValue(result)

@defer.inlineCallbacks
def do_token_login(self, login_submission):
Expand All @@ -253,7 +257,7 @@ def do_token_login(self, login_submission):
"device_id": device_id,
}

defer.returnValue((200, result))
defer.returnValue(result)

@defer.inlineCallbacks
def do_jwt_login(self, login_submission):
Expand Down Expand Up @@ -307,7 +311,7 @@ def do_jwt_login(self, login_submission):
"home_server": self.hs.hostname,
}

defer.returnValue((200, result))
defer.returnValue(result)

def _register_device(self, user_id, login_submission):
"""Register a device for a user.
Expand Down
3 changes: 3 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ def default_config(name):
config.rc_messages_per_second = 10000
config.rc_message_burst_count = 10000
config.saml2_enabled = False
config.public_baseurl = None
config.default_identity_server = None

config.use_frozen_dicts = False

# we need a sane default_room_version, otherwise attempts to create rooms will
Expand Down