|
@@ -0,0 +1,37 @@
|
|
|
+"""
|
|
|
+try to use djadhere to authenticate users in matrix
|
|
|
+cf https://github.com/matrix-org/matrix-synapse-ldap3/blob/master/ldap_auth_provider.py
|
|
|
+"""
|
|
|
+
|
|
|
+import treq
|
|
|
+from twisted.internet import defer
|
|
|
+from twisted.web import http
|
|
|
+
|
|
|
+
|
|
|
+class SynapseDjadhere(object):
|
|
|
+ def __init__(self, config, account_handler):
|
|
|
+ self.auth_api_token = config.auth_api_token
|
|
|
+
|
|
|
+ @defer.inlineCallbacks
|
|
|
+ def check_password(self, user_id, password):
|
|
|
+ localpart = user_id.split(":", 1)[0][1:]
|
|
|
+
|
|
|
+ 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)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def parse_config(config):
|
|
|
+ class _DjadhereConf(object):
|
|
|
+ pass
|
|
|
+
|
|
|
+ conf = _DjadhereConf()
|
|
|
+ if 'auth_api_token' not in config:
|
|
|
+ raise Exception('Synapse-Djadhere needs AUTH_API_TOKEN')
|
|
|
+ conf.auth_api_token = config['auth_api_token']
|
|
|
+
|
|
|
+ return conf
|