element-hq / element-hq/synapse
"Mapping provider does not support de-duplicating Matrix IDs" when `sso.update_profile_information` config option is enabled and OidcMappingProvider's `map_user_attributes` has no `failures` parameter
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 600
- Avg merge
- 5d 22h
- Merged PRs (30d)
- 51
Description
This issue has been migrated from [#12432](https://github.com/matrix-org/synapse/issues/12432).
---
See https://github.com/matrix-org/synapse/issues/8511#issuecomment-720526849 , https://github.com/matrix-org/synapse/issues/8511#issuecomment-1094142720 and https://github.com/matrix-org/synapse/issues/8511#issuecomment-1094626714.
OidcMappingProvider code:
```py
from synapse.handlers.oidc import OidcMappingProvider
from synapse.types import map_username_to_mxid_localpart
class NextcloudOidcMappingProvider(OidcMappingProvider):
def __init__(self, config):
self._config = config
@staticmethod
def parse_config(config):
return {}
def get_remote_user_id(self, userinfo):
return userinfo["ocs"]["data"]["id"]
async def map_user_attributes(self, userinfo, token):
localpart = map_username_to_mxid_localpart(userinfo["ocs"]["data"]["id"])
display_name = userinfo["ocs"]["data"]["display-name"]
return {"localpart": localpart, "display_name": display_name}
async def get_extra_attributes(self, userinfo, token):
extras = {}
return extras
```
Trying to log in a second time with `sso.update_profile_information` enabled raises an error: "Mapping provider does not support de-duplicating Matrix IDs"
The logs show that the previous user mapping _is_ found:
```
2022-04-11 06:56:23,972 - synapse.handlers.oidc - 231 - INFO - GET-6 - Received OIDC callback for IdP oidc-nextcloud
2022-04-11 06:56:24,330 - synapse.http.client - 446 - INFO - GET-6 - Received response to POST https://cloud.xxx.net/apps/oauth2/api/v1/token: 200
2022-04-11 06:56:24,530 - synapse.http.client - 446 - INFO - GET-6 - Received response to GET https://cloud.xxx.net/ocs/v2.php/cloud/user?format=json: 200
2022-04-11 06:56:24,533 - synapse.handlers.sso - 349 - INFO - GET-6 - Found existing mapping for IdP 'oidc-nextcloud' and remote_user_id 'name': @name:xxx.net
2022-04-11 06:56:24,533 - synapse.handlers.oidc - 901 - ERROR - GET-6 - Could not map user
```
The error is raised in the following code:
https://github.com/matrix-org/synapse/blob/800ba87cc881856adae19ec40485578356398639/synapse/handlers/sso.py#L474-L475
`sso_to_matrix_id_mapper(failures)` is `oidc_response_to_user_attributes(failures)`, which calls `map_user_attributes()`.
`_call_attribute_mapper` will retry calls to `sso_to_matrix_id_mapper` until it generates an unused mxid _even though we aren't trying to register a new user_
Because `map_user_attributes()` doesn't have a `failures` parameter Synapse gives up and raises a `MappingError` instead.
Contributor guide
Assessment
This issue has not been assessed yet.