2019-02-20 05:40:15 +08:00
# Synapse REST Password provider
- [Overview ](#overview )
- [Install ](#install )
- [Configure ](#configure )
- [Integrate ](#integrate )
- [Support ](#support )
2019-06-21 20:36:33 +08:00
2019-02-20 05:40:15 +08:00
## Overview
2019-06-21 20:36:33 +08:00
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:
2017-09-18 19:46:42 +08:00
- Forums (phpBB, Discourse, etc.)
- Custom Identity stores (Keycloak, ...)
- CRMs (Wordpress, ...)
- self-hosted clouds (Nextcloud, ownCloud, ...)
2020-01-24 06:08:15 +08:00
It is mainly used with [ma1sd ](https://github.com/ma1uta/ma1sd ), the Federated Matrix Identity Server, to provide
2017-09-18 21:18:34 +08:00
missing features and offer a fully integrated solution (directory, authentication, search).
2017-08-31 04:15:22 +08:00
2019-02-20 05:40:15 +08:00
**NOTE:** This module doesn't provide direct integration with any backend. If you do not use mxisd, you will need to write
your own backend, following the [Integration section ](#integrate ). This module simply translate an anthentication result
and profile information into actionables in synapse, and adapt your user profile with what is given.
2017-08-31 04:15:22 +08:00
## Install
2020-03-27 03:01:05 +08:00
Copy in whichever directory python can pick it up as a module.
2018-12-21 06:01:05 +08:00
```
2020-03-27 03:01:05 +08:00
sudo pip install git+https://github.com/ma1uta/matrix-synapse-rest-password-provider
2018-12-21 06:01:05 +08:00
```
2017-08-31 04:15:22 +08:00
2019-02-20 05:40:15 +08:00
If the command fail, double check that the python version still matches. If not, please let us know by opening an issue.
2017-08-31 04:15:22 +08:00
## Configure
2017-09-18 19:46:42 +08:00
Add or amend the `password_providers` entry like so:
2019-02-20 05:40:15 +08:00
```yaml
2017-08-31 04:15:22 +08:00
password_providers:
- module: "rest_auth_provider.RestAuthProvider"
config:
endpoint: "http://change.me.example.com:12345"
2017-10-08 10:52:08 +08:00
```
2018-11-14 11:13:02 +08:00
Set `endpoint` to the value documented with the endpoint provider.
2017-10-08 10:52:08 +08:00
## Use
1. Install, configure, restart synapse
2. Try to login with a valid username and password for the endpoint configured
## Next steps
### Lowercase username enforcement
2018-11-14 11:13:02 +08:00
**NOTE**: This is no longer relevant as synapse natively enforces lowercase.
2017-10-08 10:58:35 +08:00
To avoid creating users accounts with uppercase characters in their usernames and running into known
issues regarding case sensitivity in synapse, attempting to login with such username will fail.
2017-10-08 10:52:08 +08:00
2017-10-08 10:58:35 +08:00
It is highly recommended to keep this feature enable, but in case you would like to disable it:
2019-02-20 05:40:15 +08:00
```yaml
2017-10-08 10:52:08 +08:00
config:
2017-09-26 20:49:32 +08:00
policy:
registration:
username:
2018-11-14 11:13:02 +08:00
enforceLowercase: false
2017-08-31 04:15:22 +08:00
```
2017-10-08 10:52:08 +08:00
### Profile auto-fill
By default, on first login, the display name is set to the one returned by the backend.
If none is given, the display name is not set.
Upon subsequent login, the display name is not changed.
2017-09-18 19:46:42 +08:00
2017-10-08 10:52:08 +08:00
If you would like to change the behaviour, you can use the following configuration items:
2019-02-20 05:40:15 +08:00
```yaml
2017-10-08 10:52:08 +08:00
config:
policy:
registration:
profile:
2018-11-14 11:13:02 +08:00
name: true
2017-10-08 10:52:08 +08:00
login:
profile:
2018-11-14 11:13:02 +08:00
name: false
2017-10-08 10:52:08 +08:00
```
2017-09-26 20:49:32 +08:00
2017-10-08 10:52:08 +08:00
3PIDs received from the backend are merged with the ones already linked to the account.
2019-02-22 00:02:07 +08:00
If you would like to change this behaviour, you can use the following configuration items:
2019-02-20 05:29:55 +08:00
```yaml
config:
policy:
all:
threepid:
update: false
2019-02-22 00:02:07 +08:00
replace: false
2019-02-20 05:29:55 +08:00
```
2019-02-22 00:02:07 +08:00
If update is set to `false` , the 3PIDs will not be changed at all. If replace is set to `true` , all 3PIDs not available in the backend anymore will be deleted from synapse.
2017-08-31 04:15:22 +08:00
2017-09-18 19:46:42 +08:00
## Integrate
2019-02-15 00:26:57 +08:00
To use this module with your back-end, you will need to implement a single REST endpoint:
2017-09-18 19:46:42 +08:00
Path: `/_matrix-internal/identity/v1/check_credentials`
Method: POST
Body as JSON UTF-8:
2019-02-20 05:40:15 +08:00
```json
2017-08-31 04:15:22 +08:00
{
"user": {
"id": "@matrix.id.of.the.user:example.com",
"password": "passwordOfTheUser"
}
}
```
2019-02-20 05:40:15 +08:00
If the credentials are accepted, the following JSON answer will be provided:
```json
2017-08-31 04:15:22 +08:00
{
2017-09-26 10:21:55 +08:00
"auth": {
2019-02-20 05:40:15 +08:00
"success": true,
"mxid": "@matrix.id.of.the.user:example.com",
2017-09-26 10:21:55 +08:00
"profile": {
"display_name": "John Doe",
"three_pids": [
{
"medium": "email",
"address": "john.doe@example.org"
},
{
"medium": "msisdn",
"address": "123456789"
}
]
}
2017-08-31 04:15:22 +08:00
}
}
```
2019-02-20 05:40:15 +08:00
`auth.profile` and any sub-key are optional.
---
If the credentials are refused, the following JSON answer will be provided:
```json
{
"auth": {
"success": false
}
}
```