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

Commit

Permalink
SAML: Allow specifying the IdP entityid to use. (#8630)
Browse files Browse the repository at this point in the history
If the SAML metadata includes multiple IdPs it is necessary to
specify which IdP to redirect users to for authentication.
  • Loading branch information
benbz authored Nov 19, 2020
1 parent 950bb03 commit 53a6f5d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/8630.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow specification of the SAML IdP if the metadata returns multiple IdPs.
8 changes: 8 additions & 0 deletions docs/sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,14 @@ saml2_config:
# - attribute: department
# value: "sales"

# If the metadata XML contains multiple IdP entities then the `idp_entityid`
# option must be set to the entity to redirect users to.
#
# Most deployments only have a single IdP entity and so should omit this
# option.
#
#idp_entityid: 'https://our_idp/entityid'


# Enable OpenID Connect (OIDC) / OAuth 2.0 for registration and login.
#
Expand Down
10 changes: 10 additions & 0 deletions synapse/config/saml2_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def read_config(self, config, **kwargs):
"grandfathered_mxid_source_attribute", "uid"
)

self.saml2_idp_entityid = saml2_config.get("idp_entityid", None)

# user_mapping_provider may be None if the key is present but has no value
ump_dict = saml2_config.get("user_mapping_provider") or {}

Expand Down Expand Up @@ -383,6 +385,14 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
# value: "staff"
# - attribute: department
# value: "sales"
# If the metadata XML contains multiple IdP entities then the `idp_entityid`
# option must be set to the entity to redirect users to.
#
# Most deployments only have a single IdP entity and so should omit this
# option.
#
#idp_entityid: 'https://our_idp/entityid'
""" % {
"config_dir_path": config_dir_path
}
Expand Down
3 changes: 2 additions & 1 deletion synapse/handlers/saml_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class SamlHandler(BaseHandler):
def __init__(self, hs: "synapse.server.HomeServer"):
super().__init__(hs)
self._saml_client = Saml2Client(hs.config.saml2_sp_config)
self._saml_idp_entityid = hs.config.saml2_idp_entityid
self._auth_handler = hs.get_auth_handler()
self._registration_handler = hs.get_registration_handler()

Expand Down Expand Up @@ -100,7 +101,7 @@ def handle_redirect_request(
URL to redirect to
"""
reqid, info = self._saml_client.prepare_for_authenticate(
relay_state=client_redirect_url
entityid=self._saml_idp_entityid, relay_state=client_redirect_url
)

# Since SAML sessions timeout it is useful to log when they were created.
Expand Down

0 comments on commit 53a6f5d

Please sign in to comment.