element-hq / synapse

Synapse: Matrix homeserver written in Python/Twisted.
https://element-hq.github.io/synapse
GNU Affero General Public License v3.0
1.26k stars 155 forks source link

Mapping the existing Keycloak user to the existing synapse user, avoiding the creation of a new user #17472

Open mohammadll opened 1 month ago

mohammadll commented 1 month ago

Description

I have integrated Keycloak with Matrix Synapse, and the integration appears to be working correctly. However, I am encountering an issue with user mapping. Specifically, I want to map my existing Synapse users to their corresponding Keycloak users. When I attempt to log in using Keycloak, it seems to try to create a new user instead of mapping to the existing one. For instance, I have a user named mohammad in both Synapse and Keycloak, but when I log in with Keycloak, Synapse attempts to create a new user with a username like @mohammad1:matrix.myorg.com instead of mapping to the existing mohammad user.

My current Configuration:

oidc_providers:
  - idp_id: keycloak
    idp_name: "KeyCloak"
    issuer: "https://keycloak.example.com/realms/synapse"
    client_id: "synapse"
    client_secret: "9ejtUop8PUJh43weYtN8jGVBjGXwFFghVt"
    scopes: ["openid", "profile"]
    user_mapping_provider:
    config:
        localpart_template: "{{ user.preferred_username }}"
        display_name_template: "{{ user.name }}"

Steps to reproduce

Homeserver

matrix.myorg.com

Synapse Version

1.107.0

Installation Method

Docker (matrixdotorg/synapse)

Database

PostgreSQL

Workers

Single process

Platform

Running through Docker-Compose

Configuration

No response

Relevant log output

2024-07-22 17:39:05,701 - synapse.handlers.sso - 376 - INFO - GET-417 - Found existing mapping for IdP 'oidc-keycloak' and remote_user_id '77a8078a-5f24-4ae1-2195-a9c15f2fbe17': @mohammad1:matrix.myorg.com

Anything else that would be useful to know?

No response

nitesh-habilelabs commented 1 month ago

hi @mohammadll , i am also trying to login into matrix using keycloak…. but i am getting issue “M_FORBIDDEN: MatrixError: [403] Invalid login token (https://testmatrix.org.com/_matrix/client/v3/login)”

i have setup oidc_providers in matrix homeserver.yaml

can you please help

Edit - i already implemented login with keycloak into matrix and it works fine if i use element web but i need to integrate it in react native and i don’t want to use react native web.