Skip to content

Commit 6823471

Browse files
committed
Add hidden option to use appservice login for double puppeting
1 parent b599876 commit 6823471

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

mautrix/bridge/custom_puppet.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -181,24 +181,25 @@ async def _login_with_shared_secret(cls, mxid: UserID) -> str:
181181
base_url = cls.az.intent.api.base_url
182182
else:
183183
raise AutologinError(f"No homeserver URL configured for {server}")
184-
password = hmac.new(secret, mxid.encode("utf-8"), hashlib.sha512).hexdigest()
185184
url = base_url / str(Path.v3.login)
186-
resp = await cls.az.http_session.post(
187-
url,
188-
data=json.dumps(
189-
{
190-
"type": str(LoginType.PASSWORD),
191-
"initial_device_display_name": cls.login_device_name,
192-
"device_id": cls.login_device_name,
193-
"identifier": {
194-
"type": "m.id.user",
195-
"user": mxid,
196-
},
197-
"password": password,
198-
}
199-
),
200-
headers={"Content-Type": "application/json"},
201-
)
185+
headers = {"Content-Type": "application/json"}
186+
login_req = {
187+
"initial_device_display_name": cls.login_device_name,
188+
"device_id": cls.login_device_name,
189+
"identifier": {
190+
"type": "m.id.user",
191+
"user": mxid,
192+
},
193+
}
194+
if secret == b"appservice":
195+
login_req["type"] = str(LoginType.APPSERVICE)
196+
headers["Authorization"] = f"Bearer {cls.az.as_token}"
197+
else:
198+
login_req["type"] = str(LoginType.PASSWORD)
199+
login_req["password"] = hmac.new(
200+
secret, mxid.encode("utf-8"), hashlib.sha512
201+
).hexdigest()
202+
resp = await cls.az.http_session.post(url, data=json.dumps(login_req), headers=headers)
202203
data = await resp.json()
203204
try:
204205
return data["access_token"]

0 commit comments

Comments
 (0)