Skip to content

Commit 6c29f4d

Browse files
committed
Adapts to new module interface from Synapse v1.46.0
1 parent 90c0499 commit 6c29f4d

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

README.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# Synapse REST Password provider
2-
- [Overview](#overview)
3-
- [Install](#install)
4-
- [Configure](#configure)
5-
- [Integrate](#integrate)
6-
- [Support](#support)
2+
- [Synapse REST Password provider](#synapse-rest-password-provider)
3+
- [Overview](#overview)
4+
- [Install](#install)
5+
- [Configure](#configure)
6+
- [Use](#use)
7+
- [Next steps](#next-steps)
8+
- [Lowercase username enforcement](#lowercase-username-enforcement)
9+
- [Profile auto-fill](#profile-auto-fill)
10+
- [Integrate](#integrate)
711

812
## Overview
913
This synapse's password provider allows you to validate a password for a given username and return a user profile using an existing backend, like:
@@ -30,9 +34,9 @@ sudo pip install git+https://github.com/ma1uta/matrix-synapse-rest-password-prov
3034
If the command fail, double check that the python version still matches. If not, please let us know by opening an issue.
3135

3236
## Configure
33-
Add or amend the `password_providers` entry like so:
37+
Add or amend the `modules` entry like so:
3438
```yaml
35-
password_providers:
39+
modules:
3640
- module: "rest_auth_provider.RestAuthProvider"
3741
config:
3842
endpoint: "http://change.me.example.com:12345"

rest_auth_provider.py

+25-5
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,39 @@ def __init__(self, config, account_handler):
4242
logger.info('Endpoint: %s', self.endpoint)
4343
logger.info('Enforce lowercase username during registration: %s', self.regLower)
4444

45+
account_handler.register_password_auth_provider_callbacks(
46+
auth_checkers={
47+
("m.login.password", ("password",)): self.check_pass,
48+
},
49+
check_3pid_auth={
50+
self.check_3pid_auth
51+
}
52+
)
53+
4554
async def check_3pid_auth(self, medium, address, password):
4655
logger.info("Got password check for " + address)
4756
if medium != "email":
4857
reason = "Medium is not email. Unsuported medium for login using the rest-password-provider. Only username and email is supported."
4958
logger.warning(reason)
5059
return None
5160
login_result = await self.check_password(user_id=address,password=password)
52-
if not login_result:
61+
if login_result:
62+
return self.account_handler.get_qualified_user_id(address), None
63+
return None
64+
65+
async def check_pass(
66+
self,
67+
username: str,
68+
login_type: str,
69+
login_dict: "synapse.module_api.JsonDict",
70+
):
71+
if login_type != "m.login.password":
5372
return None
54-
return address
55-
56-
async def on_logged_out(self, user_id, device_id, access_token):
57-
return True
73+
matrix_user_id = self.account_handler.get_qualified_user_id(username)
74+
is_valid = await self.check_password(matrix_user_id,login_dict.get("password"))
75+
if is_valid:
76+
return matrix_user_id, None
77+
return None
5878

5979
async def check_password(self, user_id, password):
6080
logger.info("Got password check for " + user_id)

0 commit comments

Comments
 (0)