From 564cc0bf2cd43b50127083f27932318ddb7d43da Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Wed, 28 Aug 2019 08:11:33 +0100 Subject: [PATCH 1/3] Register clients with user_type "bot" Depends on https://github.com/matrix-org/synapse/pull/5902 This means that synapse servers that require consent will not demand it from bot users. --- maubot/management/api/client_auth.py | 1 + 1 file changed, 1 insertion(+) diff --git a/maubot/management/api/client_auth.py b/maubot/management/api/client_auth.py index 81bdb6d..2d43106 100644 --- a/maubot/management/api/client_auth.py +++ b/maubot/management/api/client_auth.py @@ -93,6 +93,7 @@ async def register(request: web.Request) -> web.Response: "password": password, "admin": False, "mac": mac, + "user_type": "bot", })) except MatrixRequestError as e: return web.json_response({ From d8c58504c5e120615783f92cf0d89ca8b052659d Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Wed, 28 Aug 2019 08:30:06 +0100 Subject: [PATCH 2/3] Pull user_type from the request --- maubot/management/api/client_auth.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/maubot/management/api/client_auth.py b/maubot/management/api/client_auth.py index 2d43106..cf4d845 100644 --- a/maubot/management/api/client_auth.py +++ b/maubot/management/api/client_auth.py @@ -74,7 +74,8 @@ async def read_client_auth_request(request: web.Request) -> Tuple[Optional[AuthR except KeyError: return None, resp.invalid_server api = HTTPAPI(base_url, "", loop=get_loop()) - return (api, secret, username, password), None + user_type = body.get("user_type", None) + return (api, secret, username, password, user_type), None @routes.post("/client/auth/{server}/register") @@ -82,7 +83,7 @@ async def register(request: web.Request) -> web.Response: info, err = await read_client_auth_request(request) if err is not None: return err - api, secret, username, password = info + api, secret, username, password, user_type = info res = await api.request(Method.GET, Path.admin.register) nonce = res["nonce"] mac = generate_mac(secret, nonce, username, password) @@ -93,7 +94,8 @@ async def register(request: web.Request) -> web.Response: "password": password, "admin": False, "mac": mac, - "user_type": "bot", + # Older versions of synapse will ignore this field if it is None + "user_type": user_type, })) except MatrixRequestError as e: return web.json_response({ From 9fe7816b493302e98964170e2cad29dcc76a1602 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Wed, 28 Aug 2019 10:03:28 +0100 Subject: [PATCH 3/3] Ignore user_type for login --- maubot/management/api/client_auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maubot/management/api/client_auth.py b/maubot/management/api/client_auth.py index cf4d845..b0bc690 100644 --- a/maubot/management/api/client_auth.py +++ b/maubot/management/api/client_auth.py @@ -110,7 +110,7 @@ async def login(request: web.Request) -> web.Response: info, err = await read_client_auth_request(request) if err is not None: return err - api, _, username, password = info + api, _, username, password, _ = info try: return web.json_response(await api.request(Method.POST, Path.login, content={ "type": "m.login.password",