Skip to content

Commit 2742b30

Browse files
Populate IDP saml response with user profile fields.
1 parent 668670a commit 2742b30

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

idp/sso.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@
4141
$domxml->loadXML($request);
4242
$xpath = new DOMXPath($domxml);
4343

44-
// Attributes provided by the Behat step.
45-
$attributes = [
46-
'uid' => $USER->username,
47-
'email' => $USER->email,
48-
'firstname' => $USER->firstname,
49-
'lastname' => $USER->lastname
50-
];
44+
// Load profile fields into attributes.
45+
$authplugin = get_auth_plugin('saml2');
46+
$userfields = array_merge($authplugin->userfields, $authplugin->get_custom_user_profile_fields());
47+
profile_load_data($USER);
48+
// Add username as `uid` as many services look for `uid` by default.
49+
$attributes = ['uid' => $USER->username];
50+
foreach ($userfields as $field) {
51+
$attributes[$field] = $USER->$field ? $USER->$field : '';
52+
}
5153

5254
// Get data from input request.
5355
$id = $xpath->evaluate('normalize-space(/*/@ID)');

0 commit comments

Comments
 (0)