From 2742b30de37e8030bba983d4ce58fe9bdda4f70d Mon Sep 17 00:00:00 2001 From: Mark Webster Date: Mon, 18 Nov 2024 13:14:07 +0000 Subject: [PATCH] Populate IDP saml response with user profile fields. --- idp/sso.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/idp/sso.php b/idp/sso.php index bdd0cb4c2..1663c8e41 100644 --- a/idp/sso.php +++ b/idp/sso.php @@ -41,13 +41,15 @@ $domxml->loadXML($request); $xpath = new DOMXPath($domxml); -// Attributes provided by the Behat step. -$attributes = [ - 'uid' => $USER->username, - 'email' => $USER->email, - 'firstname' => $USER->firstname, - 'lastname' => $USER->lastname -]; +// Load profile fields into attributes. +$authplugin = get_auth_plugin('saml2'); +$userfields = array_merge($authplugin->userfields, $authplugin->get_custom_user_profile_fields()); +profile_load_data($USER); +// Add username as `uid` as many services look for `uid` by default. +$attributes = ['uid' => $USER->username]; +foreach ($userfields as $field) { + $attributes[$field] = $USER->$field ? $USER->$field : ''; +} // Get data from input request. $id = $xpath->evaluate('normalize-space(/*/@ID)');