EZProxy, Drupal Auth and SOPAC 2

You are viewing a wiki page. You are welcome to join the group and then edit it. Be bold!

Most probably already have a module local as this is so easy but here is a snippet people can work off of. The code below doesn't do much error checking or anything. You'd likely want to edit the below to make it more robust. The one below checks a SOPAC 2 table to make sure that they have a verified library card associated with the account. This prevents normal drupal accounts that don't have a library card from accessing resources. If you use some other module to add cards to profiles you would want to use that field instead. You may also want to use SSL though I haven't checked how well EZProxy handles it for external script auth. This presumes your using normal drupal accounts and not things like LDAP, etc.

For ezproxy you would use something like this for your auth:

::external=http://yourdrupallib.org/ezproxyauth,post=ezuser=^u&ezpass=^p,valid=+OK

Feel free to edit the below to make it better.

<?php
function ezproxy_menu() {

 
$items = array();

 
$items['ezproxyauth'] = array(
   
'title' => 'EZProxy Auth',
   
'page callback' => 'ezproxy_auth',
   
'access arguments' => array('access ezproxy content'),
   
'type' => MENU_CALLBACK
 
);

  return
$items;
}

function
ezproxy_perm() {
return array(
'access ezproxy content');
}

function
ezproxy_auth() {
$dbq = db_query("SELECT uid FROM users WHERE name = '%s' AND pass = md5('%s') LIMIT 1", $_POST[ezuser], $_POST[ezpass]);
$dbres = db_fetch_array($dbq);
if (
$dbres[uid]) {
    
$uid = $dbres[uid];
       
$dbq = db_query("SELECT COUNT(*) AS valid FROM sopac_card_verify WHERE uid = '$uid' AND cardnum IS NOT NULL AND verified = '1'");
       
$dbres = db_fetch_array($dbq);
     if (
$dbres[valid]) {
           echo
"+OK";
      } else {
           echo
"+FAIL";
        }
  } else {
       echo
"+FAIL";
    }
}
?>

There is now a module for integrating EZproxy with Drupal (http://drupal.org/project/ezproxy)

Groups: