Wednesday, May 8, 2019

Mapping aditional attributes coming from SimpleSAML ADFS


For example , consider if ADFS SSO giving additional parameters like first name, surname, job title, etc., so how we map these additional attributes?
The 'simplesamlphp_auth' module gives us the option to map username, email, etc., from its user sync configuration page, buts it's not sufficient to map all fields. So here I would like to mention a way to map the additional fields.

There is a hook available for this.

hook_simplesamlphp_auth_user_attributes

I have a module named general in my code path. So I will write the above hook like below.

<?php
/**
 * Mapping of additional parameters/SAML attributes to Drupal user profile fields.
 * @param \Drupal\user\UserInterface $account
 *   The Drupal account/user
 * @param array $attributes
 *   The SimpleSAMLphp attributes for this account.
 */

function general_simplesamlphp_auth_user_attributes(\Drupal\user\UserInterface $account, $attributes) {
  $first_name = $attributes['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name'];
  $sur_name = $attributes['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname'];
  $job_title = $attributes['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/jobtitle'];

  $account->set('field_first_name', $saml_first_name);
  $account->set('field_last_name', $sur_name); 
  $account->set('field_job_title', $job_title);
  return $account;

}
?>

SSO Implementation using SimpleSAML - in Drupal


A great tutorial here : https://www.chapterthree.com/blog/how-to-configure-simplesamlphp-for-drupal-8-on-acquia

After successfully setting the library and modules you have to send the metadata to the ADFS provider.
They will send you an XML adfs metadata.
You need to convert the XML metadata into PHP array, for that please go to the simplesaml configuration page. Which is normally http://www.examplesite.com/simplesaml
Go to Federation tab
Click the link labelled 'XML to SimpleSAMLphp metadata converter'. Which will ask you to log-in(if you are not logged in)
Paste the XML metadata/or upload the XML file here and click parse, you will get the required PHP array
Copy and paste the content in /simplesamlphp/metadata/saml20-idp-remote.php