summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2020-02-25 13:45:26 +0000
committerAndrew Morgan <andrew@amorgan.xyz>2020-02-25 13:45:26 +0000
commit136caf422183d6beac727f96badc1aea265af43b (patch)
tree16c54c5528b57685a855b608560c4f771ec49c91
parentRemove origin parameter from add_display_name_to_third_party_invite and add p... (diff)
parentFix existing v2 identity server calls (MSC2140) (#6013) (diff)
downloadsynapse-136caf422183d6beac727f96badc1aea265af43b.tar.xz
Fix existing v2 identity server calls (MSC2140) (#6013)
-rw-r--r--changelog.d/6013.misc1
-rw-r--r--synapse/handlers/identity.py28
-rw-r--r--tests/handlers/test_federation.py1
-rw-r--r--tests/handlers/test_identity.py1
4 files changed, 28 insertions, 3 deletions
diff --git a/changelog.d/6013.misc b/changelog.d/6013.misc
new file mode 100644

index 0000000000..939fe8c655 --- /dev/null +++ b/changelog.d/6013.misc
@@ -0,0 +1 @@ +Compatibility with v2 Identity Service APIs other than /lookup. \ No newline at end of file diff --git a/synapse/handlers/identity.py b/synapse/handlers/identity.py
index ba12134229..cbce06ac84 100644 --- a/synapse/handlers/identity.py +++ b/synapse/handlers/identity.py
@@ -86,6 +86,25 @@ class IdentityHandler(BaseHandler): id_access_token = creds.get("id_access_token") return client_secret, id_server, id_access_token + def create_id_access_token_header(self, id_access_token): + """Create an Authorization header for passing to SimpleHttpClient as the header value + of an HTTP request. + + Args: + id_access_token (str): An identity server access token. + + Returns: + list[str]: The ascii-encoded bearer token encased in a list. + """ + # Prefix with Bearer + bearer_token = "Bearer %s" % id_access_token + + # Encode headers to standard ascii + bearer_token.encode("ascii") + + # Return as a list as that's how SimpleHttpClient takes header values + return [bearer_token] + @defer.inlineCallbacks def threepid_from_creds(self, id_server, creds): """ @@ -180,15 +199,20 @@ class IdentityHandler(BaseHandler): id_server_host = id_server # Decide which API endpoint URLs to use + headers = {} bind_data = {"sid": sid, "client_secret": client_secret, "mxid": mxid} if use_v2: bind_url = "https://%s/_matrix/identity/v2/3pid/bind" % (id_server_host,) - bind_data["id_access_token"] = id_access_token + headers["Authorization"] = self.create_id_access_token_header( + id_access_token + ) else: bind_url = "https://%s/_matrix/identity/api/v1/3pid/bind" % (id_server_host,) try: - data = yield self.http_client.post_json_get_json(bind_url, bind_data) + data = yield self.http_client.post_json_get_json( + bind_url, bind_data, headers=headers + ) logger.debug("bound threepid %r to %s", creds, mxid) # Remember where we bound the threepid diff --git a/tests/handlers/test_federation.py b/tests/handlers/test_federation.py
index b1ae15a2bd..15b694b294 100644 --- a/tests/handlers/test_federation.py +++ b/tests/handlers/test_federation.py
@@ -50,7 +50,6 @@ class FederationTestCase(unittest.HomeserverTestCase): ) d = self.handler.on_exchange_third_party_invite_request( - origin="example.com", room_id=room_id, event_dict={ "type": EventTypes.Member, diff --git a/tests/handlers/test_identity.py b/tests/handlers/test_identity.py
index 32c31b2f66..e312f72f7c 100644 --- a/tests/handlers/test_identity.py +++ b/tests/handlers/test_identity.py
@@ -91,6 +91,7 @@ class ThreepidISRewrittenURLTestCase(unittest.HomeserverTestCase): "client_secret": creds["client_secret"], "mxid": self.user_id, }, + headers={}, ) # Check that the original server name is saved in the database instead of the