@@ -86,6 +86,25 @@ def _extract_items_from_creds_dict(self, creds):
86
86
id_access_token = creds .get ("id_access_token" )
87
87
return client_secret , id_server , id_access_token
88
88
89
+ def create_id_access_token_header (self , id_access_token ):
90
+ """Create an Authorization header for passing to SimpleHttpClient as the header value
91
+ of an HTTP request.
92
+
93
+ Args:
94
+ id_access_token (str): An identity server access token.
95
+
96
+ Returns:
97
+ list[str]: The ascii-encoded bearer token encased in a list.
98
+ """
99
+ # Prefix with Bearer
100
+ bearer_token = "Bearer %s" % id_access_token
101
+
102
+ # Encode headers to standard ascii
103
+ bearer_token .encode ("ascii" )
104
+
105
+ # Return as a list as that's how SimpleHttpClient takes header values
106
+ return [bearer_token ]
107
+
89
108
@defer .inlineCallbacks
90
109
def threepid_from_creds (self , id_server , creds ):
91
110
"""
@@ -180,15 +199,20 @@ def bind_threepid(self, creds, mxid, use_v2=True):
180
199
id_server_host = id_server
181
200
182
201
# Decide which API endpoint URLs to use
202
+ headers = {}
183
203
bind_data = {"sid" : sid , "client_secret" : client_secret , "mxid" : mxid }
184
204
if use_v2 :
185
205
bind_url = "https://%s/_matrix/identity/v2/3pid/bind" % (id_server_host ,)
186
- bind_data ["id_access_token" ] = id_access_token
206
+ headers ["Authorization" ] = self .create_id_access_token_header (
207
+ id_access_token
208
+ )
187
209
else :
188
210
bind_url = "https://%s/_matrix/identity/api/v1/3pid/bind" % (id_server_host ,)
189
211
190
212
try :
191
- data = yield self .http_client .post_json_get_json (bind_url , bind_data )
213
+ data = yield self .http_client .post_json_get_json (
214
+ bind_url , bind_data , headers = headers
215
+ )
192
216
logger .debug ("bound threepid %r to %s" , creds , mxid )
193
217
194
218
# Remember where we bound the threepid
0 commit comments