From c5edf1492afa6ba00f46490f19af788e0de5692f Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 14 Nov 2021 01:24:32 +0200 Subject: [PATCH 1/2] Add support for the stable version of MSC2778 Signed-off-by: Tulir Asokan --- changelog.d/11335.feature | 1 + synapse/rest/client/login.py | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 changelog.d/11335.feature diff --git a/changelog.d/11335.feature b/changelog.d/11335.feature new file mode 100644 index 000000000000..9b6c1b9c23e6 --- /dev/null +++ b/changelog.d/11335.feature @@ -0,0 +1 @@ +Support the stable version of [MSC2778](https://github.com/matrix-org/matrix-doc/pull/2778): the `m.login.application_service` login type. Contributed by @tulir. diff --git a/synapse/rest/client/login.py b/synapse/rest/client/login.py index d49a647b0314..2fb8a7e1ac5f 100644 --- a/synapse/rest/client/login.py +++ b/synapse/rest/client/login.py @@ -61,7 +61,8 @@ class LoginRestServlet(RestServlet): TOKEN_TYPE = "m.login.token" JWT_TYPE = "org.matrix.login.jwt" JWT_TYPE_DEPRECATED = "m.login.jwt" - APPSERVICE_TYPE = "uk.half-shot.msc2778.login.application_service" + APPSERVICE_TYPE = "m.login.application_service" + APPSERVICE_TYPE_UNSTABLE = "uk.half-shot.msc2778.login.application_service" REFRESH_TOKEN_PARAM = "org.matrix.msc2918.refresh_token" def __init__(self, hs: "HomeServer"): @@ -142,6 +143,7 @@ def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]: flows.extend({"type": t} for t in self.auth_handler.get_supported_login_types()) + flows.append({"type": LoginRestServlet.APPSERVICE_TYPE_UNSTABLE}) flows.append({"type": LoginRestServlet.APPSERVICE_TYPE}) return 200, {"flows": flows} @@ -159,7 +161,10 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, LoginResponse]: should_issue_refresh_token = False try: - if login_submission["type"] == LoginRestServlet.APPSERVICE_TYPE: + if login_submission["type"] in ( + LoginRestServlet.APPSERVICE_TYPE, + LoginRestServlet.APPSERVICE_TYPE_UNSTABLE, + ): appservice = self.auth.get_appservice_by_req(request) if appservice.is_rate_limited(): From 9a95009842873940a7a6a3452d1ed31084700238 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 14 Nov 2021 01:46:13 +0200 Subject: [PATCH 2/2] Expect m.login.application_service in login and password provider tests Signed-off-by: Tulir Asokan --- synapse/rest/client/login.py | 2 +- tests/handlers/test_password_providers.py | 5 ++++- tests/rest/client/test_login.py | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/synapse/rest/client/login.py b/synapse/rest/client/login.py index 2fb8a7e1ac5f..467444a04135 100644 --- a/synapse/rest/client/login.py +++ b/synapse/rest/client/login.py @@ -143,8 +143,8 @@ def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]: flows.extend({"type": t} for t in self.auth_handler.get_supported_login_types()) - flows.append({"type": LoginRestServlet.APPSERVICE_TYPE_UNSTABLE}) flows.append({"type": LoginRestServlet.APPSERVICE_TYPE}) + flows.append({"type": LoginRestServlet.APPSERVICE_TYPE_UNSTABLE}) return 200, {"flows": flows} diff --git a/tests/handlers/test_password_providers.py b/tests/handlers/test_password_providers.py index 7dd4a5a36764..08e9730d4dfa 100644 --- a/tests/handlers/test_password_providers.py +++ b/tests/handlers/test_password_providers.py @@ -31,7 +31,10 @@ # (possibly experimental) login flows we expect to appear in the list after the normal # ones -ADDITIONAL_LOGIN_FLOWS = [{"type": "uk.half-shot.msc2778.login.application_service"}] +ADDITIONAL_LOGIN_FLOWS = [ + {"type": "m.login.application_service"}, + {"type": "uk.half-shot.msc2778.login.application_service"}, +] # a mock instance which the dummy auth providers delegate to, so we can see what's going # on diff --git a/tests/rest/client/test_login.py b/tests/rest/client/test_login.py index a63f04bd4167..0b90e3f80323 100644 --- a/tests/rest/client/test_login.py +++ b/tests/rest/client/test_login.py @@ -79,7 +79,10 @@ # (possibly experimental) login flows we expect to appear in the list after the normal # ones -ADDITIONAL_LOGIN_FLOWS = [{"type": "uk.half-shot.msc2778.login.application_service"}] +ADDITIONAL_LOGIN_FLOWS = [ + {"type": "m.login.application_service"}, + {"type": "uk.half-shot.msc2778.login.application_service"}, +] class LoginRestServletTestCase(unittest.HomeserverTestCase):