Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add config option for always using userinfo endpoint #7658

Merged
merged 18 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/7658.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add config option for always using userinfo endpoint for OpenID Connect with Gitlab. Contributed by Benjamin Koch.
5 changes: 5 additions & 0 deletions docs/sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,11 @@ oidc_config:
#
#skip_verification: true

# Always use userinfo endpoint. Required for providers that don't include
# user information in the token response, e.g. Gitlab.
#
#uses_userinfo: true

# An external module can be provided here as a custom solution to mapping
# attributes returned from a OIDC provider onto a matrix user.
#
Expand Down
6 changes: 6 additions & 0 deletions synapse/config/oidc_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def read_config(self, config, **kwargs):
self.oidc_userinfo_endpoint = oidc_config.get("userinfo_endpoint")
self.oidc_jwks_uri = oidc_config.get("jwks_uri")
self.oidc_skip_verification = oidc_config.get("skip_verification", False)
self.oidc_uses_userinfo = oidc_config.get("uses_userinfo", False)

ump_config = oidc_config.get("user_mapping_provider", {})
ump_config.setdefault("module", DEFAULT_USER_MAPPING_PROVIDER)
Expand Down Expand Up @@ -158,6 +159,11 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
#
#skip_verification: true

# Always use userinfo endpoint. Required for providers that don't include
# user information in the token response, e.g. Gitlab.
#
#uses_userinfo: true

# An external module can be provided here as a custom solution to mapping
# attributes returned from a OIDC provider onto a matrix user.
#
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/oidc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class OidcHandler:
def __init__(self, hs: HomeServer):
self._callback_url = hs.config.oidc_callback_url # type: str
self._scopes = hs.config.oidc_scopes # type: List[str]
self._uses_userinfo_config = hs.config.oidc_uses_userinfo # type: bool
self._client_auth = ClientAuth(
hs.config.oidc_client_id,
hs.config.oidc_client_secret,
Expand Down Expand Up @@ -224,8 +225,7 @@ def _uses_userinfo(self) -> bool:
``access_token`` with the ``userinfo_endpoint``.
"""

# Maybe that should be user-configurable and not inferred?
return "openid" not in self._scopes
return self._uses_userinfo_config or "openid" not in self._scopes

async def load_metadata(self) -> OpenIDProviderMetadata:
"""Load and validate the provider metadata.
Expand Down