We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Single Sign-On (SSO) / Pass through authentication with EE

Development and Programming

Ianjoyner's avatar
Ianjoyner
7 posts
8 years ago
Ianjoyner's avatar Ianjoyner

Our organization is using Microsoft Active Directory, SSO and Kerberos (apache mod_auth_kerb) to try and automatically login into Expression Engine in a Windows environment. Does anyone have any experience or code doing this? We have the SSO part working and now I’m trying to get EE to use that information to login the user. The PHP variable $_SERVER[‘REMOTE_USER’] is set and passed when the user is logged into their computer.

What I would like is for the EE to log the person in when that variable is detected or when logging into EE check for that variable. The best I have been able to figure out is to hook into the sessions_end hook. I have it mostly working but I thought it might be cleaner to use the sessions_start hook. Or some other hook that only triggers during the authentication process… but I have found no such hook.

Any other thoughts?

       
Ianjoyner's avatar
Ianjoyner
7 posts
8 years ago
Ianjoyner's avatar Ianjoyner

Here is my code. It is a method (same name as the hook) in my extension triggered the sessions_end hook. If the user isn’t found they will be prompted to login via the normal login form.

function sessions_end($user_session) {
  if ((! $user_session->session_exists) && ($user_session->validation == 'c')) {
   if ((! empty($_SERVER['REMOTE_USER'])) && (! empty($_SERVER['AUTH_TYPE'])) && ($_SERVER['AUTH_TYPE'] == 'Negotiate')) {
    if (! empty($username = explode("@", $_SERVER['REMOTE_USER'], 2))) {
     $member = ee()->db->get_where('members', array('username' => $username[0]));
     
     if ($member->num_rows() == 1) {
      $member_row = $member->row();
      
      $user_session->create_new_session($member_row->member_id);
      $user_session->fetch_session_data();
      $user_session->fetch_member_data();
      $user_session->userdata = array_merge($user_session->userdata, $user_session->sdata);
     }
     
     $member->free_result();
    }
   }
  }
 }

Are there any flaws or better ways to approach this?

       
Ianjoyner's avatar
Ianjoyner
7 posts
8 years ago
Ianjoyner's avatar Ianjoyner

The main flaw I found is logout no longer works because the sessions_end will immediately log the user back in.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.