Skip to content

Commit dd05cc5

Browse files
odelcroisandhose
andauthored
Add passthrough_authorization_parameters support to OIDC configuration (#18232)
# Add passthrough_authorization_parameters support to OIDC configuration This PR adds `the passthrough_authorization_parameters` option to OIDC configuration, allowing specific query parameters (like `login_hint`) to be passed from the redirect endpoint to the authorization grant URL. This enables clients to provide additional context to identity providers during authentication flows. # Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [x] Pull request is based on the develop branch * [x] Pull request includes a [changelog file](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#changelog). The entry should: - Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from `EventStore` to `EventWorkerStore`.". - Use markdown where necessary, mostly for `code blocks`. - End with either a period (.) or an exclamation mark (!). - Start with a capital letter. - Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry. * [x] [Code style](https://element-hq.github.io/synapse/latest/code_style.html) is correct (run the [linters](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#run-the-linters)) --------- Co-authored-by: Quentin Gliech <[email protected]>
1 parent 081f6ad commit dd05cc5

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

changelog.d/18232.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add `passthrough_authorization_parameters` in OIDC configuration to allow to pass parameters to the authorization grant URL.

docs/usage/configuration/config_documentation.md

+4
Original file line numberDiff line numberDiff line change
@@ -3672,6 +3672,9 @@ Options for each entry include:
36723672
* `additional_authorization_parameters`: String to string dictionary that will be passed as
36733673
additional parameters to the authorization grant URL.
36743674

3675+
* `passthrough_authorization_parameters`: List of parameters that will be passed through from the redirect endpoint
3676+
to the authorization grant URL.
3677+
36753678
* `allow_existing_users`: set to true to allow a user logging in via OIDC to
36763679
match a pre-existing account instead of failing. This could be used if
36773680
switching from password logins to OIDC. Defaults to false.
@@ -3798,6 +3801,7 @@ oidc_providers:
37983801
jwks_uri: "https://accounts.example.com/.well-known/jwks.json"
37993802
additional_authorization_parameters:
38003803
acr_values: 2fa
3804+
passthrough_authorization_parameters: ["login_hint"]
38013805
skip_verification: true
38023806
enable_registration: true
38033807
user_mapping_provider:

synapse/config/oidc.py

+6
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,9 @@ def _parse_oidc_config_dict(
356356
additional_authorization_parameters=oidc_config.get(
357357
"additional_authorization_parameters", {}
358358
),
359+
passthrough_authorization_parameters=oidc_config.get(
360+
"passthrough_authorization_parameters", []
361+
),
359362
)
360363

361364

@@ -501,3 +504,6 @@ class OidcProviderConfig:
501504

502505
# Additional parameters that will be passed to the authorization grant URL
503506
additional_authorization_parameters: Mapping[str, str]
507+
508+
# Allow query parameters to the redirect endpoint that will be passed to the authorization grant URL
509+
passthrough_authorization_parameters: Collection[str]

synapse/handlers/oidc.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,10 @@ def __init__(
467467

468468
self._sso_handler.register_identity_provider(self)
469469

470+
self.passthrough_authorization_parameters = (
471+
provider.passthrough_authorization_parameters
472+
)
473+
470474
def _validate_metadata(self, m: OpenIDProviderMetadata) -> None:
471475
"""Verifies the provider metadata.
472476
@@ -1005,7 +1009,6 @@ async def handle_redirect_request(
10051009
when everything is done (or None for UI Auth)
10061010
ui_auth_session_id: The session ID of the ongoing UI Auth (or
10071011
None if this is a login).
1008-
10091012
Returns:
10101013
The redirect URL to the authorization endpoint.
10111014
@@ -1078,6 +1081,13 @@ async def handle_redirect_request(
10781081
)
10791082
)
10801083

1084+
# add passthrough additional authorization parameters
1085+
passthrough_authorization_parameters = self.passthrough_authorization_parameters
1086+
for parameter in passthrough_authorization_parameters:
1087+
parameter_value = parse_string(request, parameter)
1088+
if parameter_value:
1089+
additional_authorization_parameters.update({parameter: parameter_value})
1090+
10811091
authorization_endpoint = metadata.get("authorization_endpoint")
10821092
return prepare_grant_uri(
10831093
authorization_endpoint,

tests/handlers/test_oidc.py

+26
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,32 @@ def test_redirect_request(self) -> None:
484484
self.assertEqual(code_verifier, "")
485485
self.assertEqual(redirect, "http://client/redirect")
486486

487+
@override_config(
488+
{
489+
"oidc_config": {
490+
**DEFAULT_CONFIG,
491+
"passthrough_authorization_parameters": ["additional_parameter"],
492+
}
493+
}
494+
)
495+
def test_passthrough_parameters(self) -> None:
496+
"""The redirect request has additional parameters, one is authorized, one is not"""
497+
req = Mock(spec=["cookies", "args"])
498+
req.cookies = []
499+
req.args = {}
500+
req.args[b"additional_parameter"] = ["a_value".encode("utf-8")]
501+
req.args[b"not_authorized_parameter"] = ["any".encode("utf-8")]
502+
503+
url = urlparse(
504+
self.get_success(
505+
self.provider.handle_redirect_request(req, b"http://client/redirect")
506+
)
507+
)
508+
509+
params = parse_qs(url.query)
510+
self.assertEqual(params["additional_parameter"], ["a_value"])
511+
self.assertNotIn("not_authorized_parameters", params)
512+
487513
@override_config({"oidc_config": DEFAULT_CONFIG})
488514
def test_redirect_request_with_code_challenge(self) -> None:
489515
"""The redirect request has the right arguments & generates a valid session cookie."""

0 commit comments

Comments
 (0)