element-hq / element-hq/synapse

Email notifications are not automatically enabled when authenticating via SSO or using `inhibit_login`

Open
#10,882 1 comment 2 reactions 0 assignees View on GitHub
S-Tolerable T-Defect
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

This issue has been migrated from [#10882](https://github.com/matrix-org/synapse/issues/10882).

---

### Description

Users that authenticate via oidc_provider do not have email notifications enabled by default, even though the server is configured correctly and they have an email address associated with their account.

The [problem lies here](https://github.com/matrix-org/synapse/blob/b3590614da7e3e17e75530a9d4808df17be9b127/synapse/handlers/sso.py#L949-L951), where `access_token` is set to `None` in `post_registration_actions()`. This [leads to the call](https://github.com/matrix-org/synapse/blob/b3590614da7e3e17e75530a9d4808df17be9b127/synapse/handlers/register.py#L861) to `_register_email_threepid()` with a null `access_token`, which in turn causes [the condition here](https://github.com/matrix-org/synapse/blob/b3590614da7e3e17e75530a9d4808df17be9b127/synapse/handlers/register.py#L913-L917) to evaluate to false, thus preventing the [email notification pusher](https://github.com/matrix-org/synapse/blob/b3590614da7e3e17e75530a9d4808df17be9b127/synapse/handlers/register.py#L927-L937) from being added.

### Steps to reproduce

- Configure Synapse to enable email notifications for new users: `email.notif_for_new_users: true` and `email.enable_notifs: true`.
- Log in a user for the first time using a custom oidc_provider (in our case Keycloak).
- Verify that they automatically have an email address associated with their account.
- Open the user settings and see that email notifications are disabled.

I expect the email notifications to be enabled upon first login.

### Proposed Solution

One solution to this is to include `LoginType.SSO` in the `auth_result` object passed to the `post_registration_actions()` function [here](https://github.com/matrix-org/synapse/blob/b3590614da7e3e17e75530a9d4808df17be9b127/synapse/handlers/sso.py#L944-L947) so that [prior to the `_register_email_threepid()` call](https://github.com/matrix-org/synapse/blob/b3590614da7e3e17e75530a9d4808df17be9b127/synapse/handlers/register.py#L861) the `access_token` could be set to `True` if `auth_result[LoginType.SSO] == True`. (Disclaimer: I have not tried this to verify it is a good solution. The idea came from discussion with @kyrias.)

### Version information

- **Homeserver**: independent self-hosted homeserver

If not matrix.org:

- **Version**: `"server_version":"1.42.0", "python_version":"3.8.12"`

- **Install method**: Docker image `matrixdotorg/synapse:v1.42.0` (Helm chart: `https://ananace.gitlab.io/charts/matrix-synapse:2.1.x`)

- **Platform**: Kubernetes

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.