From 8d7d251c356f74a376053619f23057f0d6d8aa1e Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 28 Aug 2014 14:56:55 +0100 Subject: [PATCH] Support multiple login flows when deciding how to login. Updated cmdclient and spec. Webclient doesn't need updating for this. --- cmdclient/console.py | 9 +++++++-- docs/specification.rst | 28 +++++++++++++++------------- synapse/rest/login.py | 2 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/cmdclient/console.py b/cmdclient/console.py index a4d8145d7..7bda4000f 100755 --- a/cmdclient/console.py +++ b/cmdclient/console.py @@ -225,8 +225,13 @@ class SynapseCmd(cmd.Cmd): json_res = yield self.http_client.do_request("GET", url) print json_res - if ("type" not in json_res or "m.login.password" != json_res["type"] or - "stages" in json_res): + if "flows" not in json_res: + print "Failed to find any login flows." + defer.returnValue(False) + + flow = json_res["flows"][0] # assume first is the one we want. + if ("type" not in flow or "m.login.password" != flow["type"] or + "stages" in flow): fallback_url = self._url() + "/login/fallback" print ("Unable to login via the command line client. Please visit " "%s to login." % fallback_url) diff --git a/docs/specification.rst b/docs/specification.rst index 8df5d478a..30e4a7a3f 100644 --- a/docs/specification.rst +++ b/docs/specification.rst @@ -230,19 +230,21 @@ with all the valid login flows when requested:: The client can login via 3 paths: 1a and 1b, 2a and 2b, or 3. The client should select one of these paths. - [ - { - "type": "", - "stages": [ "", "" ] - }, - { - "type": "", - "stages": [ "", "" ] - }, - { - "type": "" - } - ] + { + "flows": [ + { + "type": "", + "stages": [ "", "" ] + }, + { + "type": "", + "stages": [ "", "" ] + }, + { + "type": "" + } + ] + } After the login is completed, the client's fully-qualified user ID and a new access token MUST be returned:: diff --git a/synapse/rest/login.py b/synapse/rest/login.py index bcf63fd2a..99e4f10aa 100644 --- a/synapse/rest/login.py +++ b/synapse/rest/login.py @@ -27,7 +27,7 @@ class LoginRestServlet(RestServlet): PASS_TYPE = "m.login.password" def on_GET(self, request): - return (200, {"type": LoginRestServlet.PASS_TYPE}) + return (200, {"flows": [{"type": LoginRestServlet.PASS_TYPE}]}) def on_OPTIONS(self, request): return (200, {})