From 83053c6bb3f887fe70ecc2d8bb09abec1a18e252 Mon Sep 17 00:00:00 2001 From: pixel21 Date: Tue, 11 Oct 2016 00:14:06 -0500 Subject: [PATCH 1/3] Pull the existing roles, the user may have when logging in --- onelogin_saml/functions.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/onelogin_saml/functions.php b/onelogin_saml/functions.php index 2fb87e8..5a948bd 100755 --- a/onelogin_saml/functions.php +++ b/onelogin_saml/functions.php @@ -206,7 +206,8 @@ function onelogin_saml_auth($auth) { if ($result && $user = user_load(key($result['user']))) { $GLOBALS['user'] = $user; $form_state['uid'] = $user->uid; - + //If a user has previously logged in, we pull the roles it already has + $roles = $user->roles; if (!empty($roles)) { try { $fields = array( From 1337dc56f9421abed520a7428668c75501db8f2a Mon Sep 17 00:00:00 2001 From: pixel21 Date: Tue, 11 Oct 2016 00:23:44 -0500 Subject: [PATCH 2/3] Look for the RelayState parameter after we receive a response from OneLogin --- onelogin_saml/functions.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/onelogin_saml/functions.php b/onelogin_saml/functions.php index 5a948bd..c088b17 100755 --- a/onelogin_saml/functions.php +++ b/onelogin_saml/functions.php @@ -52,7 +52,13 @@ function onelogin_saml_acs() { drupal_set_message("No SAML Response found.", 'error', FALSE); drupal_goto(''); } - + /*When a user logins using OneLogin and the URL has a destination parameter in it, + * we redirect them to the page after logging in + * Works because we append destination parameter to OneLogin SAML url + */ + if(isset($_POST['RelayState'])){ + drupal_goto($_POST['RelayState']); + } drupal_goto('user/' . $user->uid); } From f362975191117d817c8b42a1e9107004ad47aa96 Mon Sep 17 00:00:00 2001 From: pixel21 Date: Tue, 11 Oct 2016 00:30:16 -0500 Subject: [PATCH 3/3] Append destination parameter to Log in using SAML url --- onelogin_saml/onelogin_saml.module | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/onelogin_saml/onelogin_saml.module b/onelogin_saml/onelogin_saml.module index 993d6ea..3e94acd 100755 --- a/onelogin_saml/onelogin_saml.module +++ b/onelogin_saml/onelogin_saml.module @@ -148,8 +148,9 @@ function _onelogin_saml_user_login_form_alter(&$form, &$form_state) { if ($showSamlLink) { // Add a "Log in using SAML" link to the user-login form. $items = array(); + //Pass on a destination parameter to OneLogin. The OneLogin ldp will pass it back to us using RelayState $items[] = array( - 'data' => l(t('Log in using SAML'), url('onelogin_saml/sso', array('absolute' => true)), array('external' => TRUE)), + 'data' => l(t('Log in using SAML'), url('onelogin_saml/sso', array('absolute' => true)), array('external' => TRUE),array('query'=>array('destination'=>drupal_get_destination()))), 'class' => array('saml-link'), );