From 65ca5a7be28370d914cb7fb068a53ef2807c3dcc Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 12 Jun 2020 13:58:35 +0100 Subject: [PATCH 1/6] Update m.id.phone to use 'phone' instead of 'number' Fixes bug introduced in https://github.com/matrix-org/synapse/pull/1994 --- synapse/rest/client/v1/login.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synapse/rest/client/v1/login.py b/synapse/rest/client/v1/login.py index dceb2792fa7a..5daaacec0c6b 100644 --- a/synapse/rest/client/v1/login.py +++ b/synapse/rest/client/v1/login.py @@ -60,10 +60,10 @@ def login_id_thirdparty_from_phone(identifier): Returns: Login identifier dict of type 'm.id.threepid' """ - if "country" not in identifier or "number" not in identifier: + if "country" not in identifier or "phone" not in identifier: raise SynapseError(400, "Invalid phone-type identifier") - msisdn = phone_number_to_msisdn(identifier["country"], identifier["number"]) + msisdn = phone_number_to_msisdn(identifier["country"], identifier["phone"]) return {"type": "m.id.thirdparty", "medium": "msisdn", "address": msisdn} From 90c714dabfc753034e0d135a43aec640e887a08e Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 12 Jun 2020 14:02:02 +0100 Subject: [PATCH 2/6] Changelog --- changelog.d/7687.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/7687.bugfix diff --git a/changelog.d/7687.bugfix b/changelog.d/7687.bugfix new file mode 100644 index 000000000000..03bc4883aed5 --- /dev/null +++ b/changelog.d/7687.bugfix @@ -0,0 +1 @@ +Correct Synapse's definition of `m.id.phone`, changing `number` to `phone`. Bug introduced in #1994. From 91c1b7047bf56c7fd8ddab811472b2fae126937a Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 12 Jun 2020 14:21:25 +0100 Subject: [PATCH 3/6] Allow for old and new key name --- synapse/rest/client/v1/login.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/synapse/rest/client/v1/login.py b/synapse/rest/client/v1/login.py index 5daaacec0c6b..81b9429c4f0a 100644 --- a/synapse/rest/client/v1/login.py +++ b/synapse/rest/client/v1/login.py @@ -60,10 +60,18 @@ def login_id_thirdparty_from_phone(identifier): Returns: Login identifier dict of type 'm.id.threepid' """ - if "country" not in identifier or "phone" not in identifier: + if "country" not in identifier or ( + # XXX: We used to require `number` instead of `phone`. The spec + # defines `phone`. So accept both + "phone" not in identifier + and "number" not in identifier + ): raise SynapseError(400, "Invalid phone-type identifier") - msisdn = phone_number_to_msisdn(identifier["country"], identifier["phone"]) + # Accept both "phone" and "number" as valid keys in m.id.phone + phone_number = identifier.get("phone", identifier["number"]) + + msisdn = phone_number_to_msisdn(identifier["country"], phone_number) return {"type": "m.id.thirdparty", "medium": "msisdn", "address": msisdn} From a7c2c3266371dbb58ab408f52609e908d299f714 Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Mon, 15 Jun 2020 13:31:16 +0100 Subject: [PATCH 4/6] Update changelog.d/7687.bugfix Co-authored-by: Patrick Cloke --- changelog.d/7687.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/7687.bugfix b/changelog.d/7687.bugfix index 03bc4883aed5..038c7f782caa 100644 --- a/changelog.d/7687.bugfix +++ b/changelog.d/7687.bugfix @@ -1 +1 @@ -Correct Synapse's definition of `m.id.phone`, changing `number` to `phone`. Bug introduced in #1994. +Correct Synapse's definition of `m.id.phone`, changing `number` to `phone`. Bug introduced in v0.20.0-rc1. From 1f07f0fa4e1c7d328ab85c916c090698e5ef6ef8 Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Mon, 15 Jun 2020 15:00:21 +0100 Subject: [PATCH 5/6] Update changelog.d/7687.bugfix Co-authored-by: Patrick Cloke --- changelog.d/7687.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/7687.bugfix b/changelog.d/7687.bugfix index 038c7f782caa..0413aff0b340 100644 --- a/changelog.d/7687.bugfix +++ b/changelog.d/7687.bugfix @@ -1 +1 @@ -Correct Synapse's definition of `m.id.phone`, changing `number` to `phone`. Bug introduced in v0.20.0-rc1. +Accept the proper field (`phone`) for the `m.id.phone` identifier type. The legacy field of `number` is still accepted as a fallback. Bug introduced in v0.20.0-rc1. From cd9a005905ed334c8c7f9683017c8600f34f0ebb Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Mon, 15 Jun 2020 15:06:54 +0100 Subject: [PATCH 6/6] Clean up backwards compatibility comment --- synapse/rest/client/v1/login.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synapse/rest/client/v1/login.py b/synapse/rest/client/v1/login.py index 81b9429c4f0a..c2c9a9c3aa77 100644 --- a/synapse/rest/client/v1/login.py +++ b/synapse/rest/client/v1/login.py @@ -61,8 +61,8 @@ def login_id_thirdparty_from_phone(identifier): Returns: Login identifier dict of type 'm.id.threepid' """ if "country" not in identifier or ( - # XXX: We used to require `number` instead of `phone`. The spec - # defines `phone`. So accept both + # The specification requires a "phone" field, while Synapse used to require a "number" + # field. Accept both for backwards compatibility. "phone" not in identifier and "number" not in identifier ):