4

I'm trying to replace Drupal authentication with the authentication from a SSO server, in a scenario discussed here. I'm trying to modify the login_block (on "Homepage" as well as "Access Denied" page), and login_block_form (at mysite.com/user/login). I did reset the default "Log in" button and replaced it with "SSO Log in" button, and on its #submit, using drupal_goto, I'm trying to redirect it to SSO server Login page. But, I'm still getting redirected to mysite.com/node?destination=node. I'm not able to figure out what the problem is. And inputs would be appreciated.

function MODULE_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'user_login_block' || $form_id == 'user_login') {
    // Add a button to form, used to login to SSO
        $form['foo'] = array(
            '#type' => 'button',
            '#value' => t('SSO Log in'),
            '#submit' => array('MODULE_user_login_foo_submit'),
            '#limit_validation_errors' => array(),
        );
        // unset the current default login button of Drupal
        unset ($form['actions']['submit']);
  }
}

function MODULE_user_login_foo_submit($form, &$form_state) {
  drupal_goto('PATH/TO/SSO-SERVER-LOGIN-PAGE.ASPX', array('external' => TRUE));
}
4

Unset the destination before calling drupal_goto():

unset($_GET['destination']);
drupal_goto('PATH/TO/SSO-SERVER-LOGIN-PAGE.ASPX', array('external' => TRUE));

Another option would be to code the redirection logic yourself (brought up as an answer by Dave here).

The problem exists because drupal_goto() is overriding the given path with the destination if the latter is not external (check the function code).

Additionally:

Since you are using the button type the submit handler isn't being invoked (documentation). For my solution to work you would have to change the type to 'submit' or move the redirection logic into the validation handler (by changing '#submit' to '#validate').

  • thank you for the reply; but it didn't work :( I changed the $form['action'] to get the required redirection – AjitS Aug 20 '12 at 7:11
  • Sorry about the late reply. I forgot to mention that Drupal isn't invoking the submit handler since you're using the button type. To get my solution working you would have to change the #type value to submit or switch out #submit with #validate. Your own solution is fine as well though, just letting you know for future reference :) – Madis Sep 3 '12 at 19:08
  • I should've investigated more before going for a work-around. anyways thank you very much :) – AjitS Sep 4 '12 at 5:29
2
//implements hook_form_alter()
function MODULE_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'user_login_block' || $form_id == 'user_login') {
    $form['#action'] = 'PATH/TO/SSO-SERVER-LOGIN-PAGE.ASPX';
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.