-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Allow OIDC for existing users #8180
Changes from all commits
e8d43bc
a1821f3
0ab81d3
073b3b6
94e52a1
74e6ddd
5c0ba94
11b8138
d28b476
2b4d7b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add a configuration option that allows existing users to log in with OpenID Connect. Contributed by @BBBSnowball and @OmmyZhang. |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -114,6 +114,7 @@ def __init__(self, hs: "HomeServer"): | |||||||||||||||||||||||||
hs.config.oidc_user_mapping_provider_config | ||||||||||||||||||||||||||
) # type: OidcMappingProvider | ||||||||||||||||||||||||||
self._skip_verification = hs.config.oidc_skip_verification # type: bool | ||||||||||||||||||||||||||
self._allow_existing_users = hs.config.oidc_allow_existing_users # type: bool | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
self._http_client = hs.get_proxied_http_client() | ||||||||||||||||||||||||||
self._auth_handler = hs.get_auth_handler() | ||||||||||||||||||||||||||
|
@@ -849,7 +850,8 @@ async def _map_userinfo_to_user( | |||||||||||||||||||||||||
If we don't find the user that way, we should register the user, | ||||||||||||||||||||||||||
mapping the localpart and the display name from the UserInfo. | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
If a user already exists with the mxid we've mapped, raise an exception. | ||||||||||||||||||||||||||
If a user already exists with the mxid we've mapped and allow_existing_users | ||||||||||||||||||||||||||
is disabled , raise an exception. | ||||||||||||||||||||||||||
Comment on lines
+853
to
+854
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
Args: | ||||||||||||||||||||||||||
userinfo: an object representing the user | ||||||||||||||||||||||||||
|
@@ -906,20 +908,25 @@ async def _map_userinfo_to_user( | |||||||||||||||||||||||||
localpart = map_username_to_mxid_localpart(attributes["localpart"]) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
user_id = UserID(localpart, self._hostname) | ||||||||||||||||||||||||||
if await self._datastore.get_users_by_id_case_insensitive(user_id.to_string()): | ||||||||||||||||||||||||||
# This mxid is taken | ||||||||||||||||||||||||||
raise MappingException( | ||||||||||||||||||||||||||
"mxid '{}' is already taken".format(user_id.to_string()) | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
# It's the first time this user is logging in and the mapped mxid was | ||||||||||||||||||||||||||
# not taken, register the user | ||||||||||||||||||||||||||
registered_user_id = await self._registration_handler.register_user( | ||||||||||||||||||||||||||
localpart=localpart, | ||||||||||||||||||||||||||
default_display_name=attributes["display_name"], | ||||||||||||||||||||||||||
user_agent_ips=(user_agent, ip_address), | ||||||||||||||||||||||||||
matches = await self._datastore.get_users_by_id_case_insensitive( | ||||||||||||||||||||||||||
user_id.to_string() | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
if matches: | ||||||||||||||||||||||||||
if self._allow_existing_users: | ||||||||||||||||||||||||||
registered_user_id = next(iter(matches)) | ||||||||||||||||||||||||||
Comment on lines
+915
to
+916
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can matches have multiple items? Should we still error in that case? It feels arbitrary to choose the first one. At the very least I think we should log something. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there can't be more than one item as the same (case insensitive) usernames are not allowed. This is also why we need synapse/synapse/handlers/register.py Lines 111 to 116 in efb6b66
Maybe we should log something if there're more than one, to show that something goes wrong? But it's a little strange. If we do, we should also do this in many other places. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I find synapse/synapse/handlers/auth.py Lines 753 to 758 in efb6b66
|
||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||
# This mxid is taken | ||||||||||||||||||||||||||
raise MappingException( | ||||||||||||||||||||||||||
"mxid '{}' is already taken".format(user_id.to_string()) | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||
# It's the first time this user is logging in and the mapped mxid was | ||||||||||||||||||||||||||
# not taken, register the user | ||||||||||||||||||||||||||
registered_user_id = await self._registration_handler.register_user( | ||||||||||||||||||||||||||
localpart=localpart, | ||||||||||||||||||||||||||
default_display_name=attributes["display_name"], | ||||||||||||||||||||||||||
user_agent_ips=(user_agent, ip_address), | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
await self._datastore.record_user_external_id( | ||||||||||||||||||||||||||
self._auth_provider_id, remote_user_id, registered_user_id, | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this comment is very descriptive -- what's the token that's being added? Why would I turn this on?