|
|
|
@ -28,6 +28,7 @@ from synapse.http.servlet import ( |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
@ -95,6 +96,7 @@ class LoginRestServlet(ClientV1RestServlet): |
|
|
|
|
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 = [] |
|
|
|
@ -132,16 +134,18 @@ class LoginRestServlet(ClientV1RestServlet): |
|
|
|
|
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 |
|
|
|
@ -150,7 +154,7 @@ class LoginRestServlet(ClientV1RestServlet): |
|
|
|
|
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 |
|
|
|
@ -233,7 +237,7 @@ class LoginRestServlet(ClientV1RestServlet): |
|
|
|
|
if callback is not None: |
|
|
|
|
yield callback(result) |
|
|
|
|
|
|
|
|
|
defer.returnValue((200, result)) |
|
|
|
|
defer.returnValue(result) |
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
def do_token_login(self, login_submission): |
|
|
|
@ -253,7 +257,7 @@ class LoginRestServlet(ClientV1RestServlet): |
|
|
|
|
"device_id": device_id, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
defer.returnValue((200, result)) |
|
|
|
|
defer.returnValue(result) |
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
def do_jwt_login(self, login_submission): |
|
|
|
@ -307,7 +311,7 @@ class LoginRestServlet(ClientV1RestServlet): |
|
|
|
|
"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. |
|
|
|
|