Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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/18232.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add 'passthrough_authorization_parameters' in oidc configuration to allow to pass parameters to the authorization grant URL.
Comment thread
odelcroi marked this conversation as resolved.
Outdated
6 changes: 6 additions & 0 deletions docs/usage/configuration/config_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -3672,6 +3672,9 @@ Options for each entry include:
* `additional_authorization_parameters`: String to string dictionary that will be passed as
additional parameters to the authorization grant URL.

* `passthrough_authorization_parameters`: List of parameters that will be passed through from the redirect endpoint
to the authorization grant URL.

* `allow_existing_users`: set to true to allow a user logging in via OIDC to
match a pre-existing account instead of failing. This could be used if
switching from password logins to OIDC. Defaults to false.
Expand Down Expand Up @@ -3759,6 +3762,7 @@ Options for each entry include:

You might want to disable this if the `subject_claim` returned by the mapping provider is not `sub`.


Comment thread
odelcroi marked this conversation as resolved.
Outdated
It is possible to configure Synapse to only allow logins if certain attributes
match particular values in the OIDC userinfo. The requirements can be listed under
`attribute_requirements` as shown here:
Expand Down Expand Up @@ -3798,6 +3802,7 @@ oidc_providers:
jwks_uri: "https://accounts.example.com/.well-known/jwks.json"
additional_authorization_parameters:
acr_values: 2fa
passthrough_authorization_parameters: ["login_hint"]
skip_verification: true
enable_registration: true
user_mapping_provider:
Expand All @@ -3809,6 +3814,7 @@ oidc_providers:
attribute_requirements:
- attribute: userGroup
value: "synapseUsers"

Comment thread
odelcroi marked this conversation as resolved.
Outdated
```
---
### `cas_config`
Expand Down
6 changes: 6 additions & 0 deletions synapse/config/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ def _parse_oidc_config_dict(
additional_authorization_parameters=oidc_config.get(
"additional_authorization_parameters", {}
),
passthrough_authorization_parameters=oidc_config.get(
"passthrough_authorization_parameters", []
),
)


Expand Down Expand Up @@ -501,3 +504,6 @@ class OidcProviderConfig:

# Additional parameters that will be passed to the authorization grant URL
additional_authorization_parameters: Mapping[str, str]

# Allow query parameters to the redirect endpoint that will be passed to the authorization grant URL
passthrough_authorization_parameters: Collection[str]
13 changes: 12 additions & 1 deletion synapse/handlers/oidc.py
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be an extension of the spec, which should go through the spec change process. Given that it's unlikely that such a spec change would land, I think it would make sense to instead have a generic option to 'passthrough' specific query parameters.

Something like

oidc_providers:
  - idp_id: 
    passthrough_authorization_parameters:
      - login_hint

And then passthrough any query parameter passed to /_matrix/client/v3/login/sso/redirect to the OIDC authorization request

Copy link
Copy Markdown
Contributor Author

@odelcroi odelcroi Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for your inputs, makes sense, I've made the corresponding changes

Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,10 @@ def __init__(

self._sso_handler.register_identity_provider(self)

self.passthrough_authorization_parameters = (
provider.passthrough_authorization_parameters
)

def _validate_metadata(self, m: OpenIDProviderMetadata) -> None:
"""Verifies the provider metadata.

Expand Down Expand Up @@ -990,6 +994,7 @@ async def handle_redirect_request(
- ``state``: a random string
- ``nonce``: a random string
- ``code_challenge``: a RFC7636 code challenge (if PKCE is supported)
- ``login_hint``: provide login to avoid re-entering it in the upstream idp

In addition to generating a redirect URL, we are setting a cookie with
a signed macaroon token containing the state, the nonce, the
Expand All @@ -1005,7 +1010,6 @@ async def handle_redirect_request(
when everything is done (or None for UI Auth)
ui_auth_session_id: The session ID of the ongoing UI Auth (or
None if this is a login).

Returns:
The redirect URL to the authorization endpoint.

Expand Down Expand Up @@ -1078,6 +1082,13 @@ async def handle_redirect_request(
)
)

# add passthrough additional authorization parameters
passthrough_authorization_parameters = self.passthrough_authorization_parameters
for parameter in passthrough_authorization_parameters:
parameter_value = parse_string(request, parameter)
if parameter_value:
additional_authorization_parameters.update({parameter: parameter_value})

authorization_endpoint = metadata.get("authorization_endpoint")
return prepare_grant_uri(
authorization_endpoint,
Expand Down
26 changes: 26 additions & 0 deletions tests/handlers/test_oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,32 @@ def test_redirect_request(self) -> None:
self.assertEqual(code_verifier, "")
self.assertEqual(redirect, "http://client/redirect")

@override_config(
{
"oidc_config": {
**DEFAULT_CONFIG,
"passthrough_authorization_parameters": ["additional_parameter"],
}
}
)
def test_passthrough_parameters(self) -> None:
"""The redirect request has additional parameters, one is authorized, one is not"""
req = Mock(spec=["cookies", "args"])
req.cookies = []
req.args = {}
req.args[b"additional_parameter"] = ["a_value".encode("utf-8")]
req.args[b"not_authorized_parameter"] = ["any".encode("utf-8")]

url = urlparse(
self.get_success(
self.provider.handle_redirect_request(req, b"http://client/redirect")
)
)

params = parse_qs(url.query)
self.assertEqual(params["additional_parameter"], ["a_value"])
self.assertNotIn("not_authorized_parameters", params)

@override_config({"oidc_config": DEFAULT_CONFIG})
def test_redirect_request_with_code_challenge(self) -> None:
"""The redirect request has the right arguments & generates a valid session cookie."""
Expand Down
Loading