Simple Single-Sign-On based on Windows login information

Simple Single-Sign-On based on Windows login information

by Ole Djurhuus -
Number of replies: 3

Hi there

I am trying to make a simple SSO for my Moodle intranet site, but need som help.

My objective:

When our employees click on a link to Moodle they will automatically be logged in based on there windows login username

Solution:

1. I grab the username via the NTLM-method

2. The user gets authenticated via the username and logged in

Status:

The first step work:
// NTLM specs http://davenport.sourceforge.net/ntlm.html

$headers = apache_request_headers();

if (!isset($headers['Authorization'])){
 header('HTTP/1.1 401 Unauthorized');
 header('WWW-Authenticate: NTLM');
 exit;
}

$auth = $headers['Authorization'];

if (substr($auth,0,5) == 'NTLM ') {
 $msg = base64_decode(substr($auth, 5));
 if (substr($msg, 0, 8) != "NTLMSSP\x00")
  die('error header not recognised');

 if ($msg[8] == "\x01") {
  $msg2 = "NTLMSSP\x00\x02"."\x00\x00\x00\x00". // target name len/alloc
   "\x00\x00\x00\x00". // target name offset
   "\x01\x02\x81\x01". // flags
   "\x00\x00\x00\x00\x00\x00\x00\x00". // challenge
   "\x00\x00\x00\x00\x00\x00\x00\x00". // context
   "\x00\x00\x00\x00\x30\x00\x00\x00"; // target info len/alloc/offset

  header('HTTP/1.1 401 Unauthorized');
  header('WWW-Authenticate: NTLM '.trim(base64_encode($msg2)));
  exit;
 }
 else if ($msg[8] == "\x03") {
  function get_msg_str($msg, $start, $unicode = true) {
   $len = (ord($msg[$start+1]) * 256) + ord($msg[$start]);
   $off = (ord($msg[$start+5]) * 256) + ord($msg[$start+4]);
   if ($unicode)
    return str_replace("\0", '', substr($msg, $off, $len));
   else
    return substr($msg, $off, $len);
  }
  $user = get_msg_str($msg, 36);
  $domain = get_msg_str($msg, 28);
  $workstation = get_msg_str($msg, 44);


  print "You are $user from $domain/$workstation";
 }
}

I can't figure out how to do the last part...

Can any of you help?

Regards

Ole

Average of ratings: -
In reply to Ole Djurhuus

Re: Simple Single-Sign-On based on Windows login information

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Why don't you simply use NTLM SSO? (http://docs.moodle.org/en/NTLM_authentication).

Then you just need to set ' Force users to login' (under Administration >> Security >> Site Policies)

Saludos. Iñaki.

In reply to Iñaki Arenaza

Ang: Re: Simple Single-Sign-On based on Windows login information

by Ole Djurhuus -

Hi Iñaki

In Moodle 1.9 and onwards, NTLM authentication depends on LDAP authentication (I use Moodle 1.9.4). As for now I can't setup a LDAP service, so the NTLM SSO is not possible for me.

Regards

Ole

In reply to Ole Djurhuus

Re: Ang: Re: Simple Single-Sign-On based on Windows login information

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You know Active Directory can be queried via LDAP, don't you? So you don't need to setup a LDAP service; if you are running AD, you already have a LDAP Service smile

Saludos. Iñaki.