Browse Source

synapse_djadhere: allow auth of a bot

Guilhem Saurel 6 years ago
parent
commit
956b566c20
2 changed files with 12 additions and 2 deletions
  1. 2 0
      matrix/homeserver.yaml
  2. 10 2
      matrix/synapse_djadhere.py

+ 2 - 0
matrix/homeserver.yaml

@@ -2,3 +2,5 @@ password_providers:
     - module: "synapse_djadhere.SynapseDjadhere"
       config:
           auth_api_token: "{{ AUTH_API_TOKEN }}"
+          bot_user: "{{ BOT_USER }}"
+          bot_password: "{{ BOT_PASSWORD }}"

+ 10 - 2
matrix/synapse_djadhere.py

@@ -16,13 +16,15 @@ class SynapseDjadhere(object):
     def check_password(self, user_id, password):
         localpart = user_id.split(":", 1)[0][1:]
 
-        response = yield treq.post(
+        bot = user_id == self.bot_user and password == self.password
+
+        djadhere_response = yield treq.post(
             'https://adherents.tetaneutral.net/accounts/auth_api/%s/' %
             self.auth_api_token, {
                 'username': localpart,
                 'password': password
             })
-        defer.returnValue(response.code == http.OK)
+        defer.returnValue(bot or djadhere_response.code == http.OK)
 
     @staticmethod
     def parse_config(config):
@@ -32,6 +34,12 @@ class SynapseDjadhere(object):
         conf = _DjadhereConf()
         if 'auth_api_token' not in config:
             raise Exception('Synapse-Djadhere needs AUTH_API_TOKEN')
+        if 'bot_user' not in config:
+            raise Exception('Synapse-Djadhere needs BOT_USER')
+        if 'bot_password' not in config:
+            raise Exception('Synapse-Djadhere needs BOT_PASSWORD')
         conf.auth_api_token = config['auth_api_token']
+        conf.bot_user = config['bot_user']
+        conf.bot_password = config['bot_password']
 
         return conf