Skip to content
Snippets Groups Projects
Commit c6e777b8 authored by Tulir Asokan's avatar Tulir Asokan :cat2:
Browse files

Add option to log in to custom puppet with shared secret

parent da3bbb3d
No related branches found
No related tags found
No related merge requests found
......@@ -82,6 +82,12 @@ bridge:
# Whether or not to use /sync to get presence, read receipts and typing notifications when using
# your own Matrix account as the Matrix puppet for your Facebook account.
sync_with_custom_puppets: true
# Shared secret for https://github.com/devture/matrix-synapse-shared-secret-auth
#
# If set, custom puppets will be enabled automatically for local users
# instead of users having to find an access token and run `login-matrix`
# manually.
login_shared_secret: null
# Whether or not to bridge presence in both directions. Facebook allows users not to broadcast
# presence, but then it won't send other users' presence to the client.
presence: true
......
......@@ -36,6 +36,7 @@ class Config(BaseBridgeConfig):
copy("bridge.initial_chat_sync")
copy("bridge.invite_own_puppet_to_pm")
copy("bridge.sync_with_custom_puppets")
copy("bridge.login_shared_secret")
copy("bridge.presence")
copy("bridge.update_avatar_initial_sync")
......
......@@ -260,4 +260,7 @@ def init(context: 'Context') -> Iterable[Awaitable[None]]:
Puppet.mxid_template = SimpleTemplate(config["bridge.username_template"], "userid",
prefix="@", suffix=f":{Puppet.hs_domain}", type=str)
Puppet.login_shared_secret = config["bridge.login_shared_secret"].encode("utf-8")
Puppet.login_device_name = "Facebook Messenger Bridge"
return (puppet.try_start() for puppet in Puppet.get_all_with_custom_mxid())
......@@ -168,6 +168,16 @@ class User(Client):
async def post_login(self) -> None:
self.log.info("Running post-login actions")
self.by_fbid[self.fbid] = self
try:
puppet = pu.Puppet.get_by_fbid(self.fbid)
if puppet.custom_mxid != self.mxid and puppet.can_auto_login(self.mxid):
self.log.info(f"Automatically enabling custom puppet")
await puppet.switch_mxid(access_token="auto", mxid=self.mxid)
except Exception:
self.log.exception("Failed to automatically enable custom puppet")
await self._create_community()
await self.sync_contacts()
await self.sync_threads()
......
......@@ -33,7 +33,7 @@ setuptools.setup(
install_requires=[
"aiohttp>=3.0.1,<4",
"mautrix>=0.4.0rc2,<0.5.0",
"mautrix>=0.4.0rc4,<0.5.0",
"ruamel.yaml>=0.15.94,<0.17",
"commonmark>=0.8,<0.10",
"python-magic>=0.4,<0.5",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment