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

Allow OIDC config to override discovered values #9384

Merged
merged 1 commit into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all 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/9384.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow OIDC config to override discovered values.
27 changes: 18 additions & 9 deletions synapse/handlers/oidc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,22 +383,31 @@ async def load_metadata(self, force: bool = False) -> OpenIDProviderMetadata:
return await self._provider_metadata.get()

async def _load_metadata(self) -> OpenIDProviderMetadata:
# init the metadata from our config
metadata = OpenIDProviderMetadata(
issuer=self._config.issuer,
authorization_endpoint=self._config.authorization_endpoint,
token_endpoint=self._config.token_endpoint,
userinfo_endpoint=self._config.userinfo_endpoint,
jwks_uri=self._config.jwks_uri,
)
# start out with just the issuer (unlike the other settings, discovered issuer
# takes precedence over configured issuer, because configured issuer is
# required for discovery to take place.)
#
metadata = OpenIDProviderMetadata(issuer=self._config.issuer)

# load any data from the discovery endpoint, if enabled
if self._config.discover:
url = get_well_known_url(self._config.issuer, external=True)
metadata_response = await self._http_client.get_json(url)
# TODO: maybe update the other way around to let user override some values?
metadata.update(metadata_response)

# override any discovered data with any settings in our config
if self._config.authorization_endpoint:
metadata["authorization_endpoint"] = self._config.authorization_endpoint

if self._config.token_endpoint:
metadata["token_endpoint"] = self._config.token_endpoint

if self._config.userinfo_endpoint:
metadata["userinfo_endpoint"] = self._config.userinfo_endpoint

if self._config.jwks_uri:
metadata["jwks_uri"] = self._config.jwks_uri

self._validate_metadata(metadata)

return metadata
Expand Down