Skip to content

Commit

Permalink
Adapts to new module interface from Synapse v1.46.0
Browse files Browse the repository at this point in the history
  • Loading branch information
anishihara committed Nov 12, 2021
1 parent 90c0499 commit 6c29f4d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Synapse REST Password provider
- [Overview](#overview)
- [Install](#install)
- [Configure](#configure)
- [Integrate](#integrate)
- [Support](#support)
- [Synapse REST Password provider](#synapse-rest-password-provider)
- [Overview](#overview)
- [Install](#install)
- [Configure](#configure)
- [Use](#use)
- [Next steps](#next-steps)
- [Lowercase username enforcement](#lowercase-username-enforcement)
- [Profile auto-fill](#profile-auto-fill)
- [Integrate](#integrate)

## Overview
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:
Expand All @@ -30,9 +34,9 @@ sudo pip install git+https:/ma1uta/matrix-synapse-rest-password-prov
If the command fail, double check that the python version still matches. If not, please let us know by opening an issue.

## Configure
Add or amend the `password_providers` entry like so:
Add or amend the `modules` entry like so:
```yaml
password_providers:
modules:
- module: "rest_auth_provider.RestAuthProvider"
config:
endpoint: "http://change.me.example.com:12345"
Expand Down
30 changes: 25 additions & 5 deletions rest_auth_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,39 @@ def __init__(self, config, account_handler):
logger.info('Endpoint: %s', self.endpoint)
logger.info('Enforce lowercase username during registration: %s', self.regLower)

account_handler.register_password_auth_provider_callbacks(
auth_checkers={
("m.login.password", ("password",)): self.check_pass,
},
check_3pid_auth={
self.check_3pid_auth
}
)

async def check_3pid_auth(self, medium, address, password):
logger.info("Got password check for " + address)
if medium != "email":
reason = "Medium is not email. Unsuported medium for login using the rest-password-provider. Only username and email is supported."
logger.warning(reason)
return None
login_result = await self.check_password(user_id=address,password=password)
if not login_result:
if login_result:
return self.account_handler.get_qualified_user_id(address), None
return None

async def check_pass(
self,
username: str,
login_type: str,
login_dict: "synapse.module_api.JsonDict",
):
if login_type != "m.login.password":
return None
return address

async def on_logged_out(self, user_id, device_id, access_token):
return True
matrix_user_id = self.account_handler.get_qualified_user_id(username)
is_valid = await self.check_password(matrix_user_id,login_dict.get("password"))
if is_valid:
return matrix_user_id, None
return None

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

0 comments on commit 6c29f4d

Please sign in to comment.