EZProxy, Drupal Auth and SOPAC 2

Events happening in the community are now at Drupal community events on www.drupal.org.
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)

jblyberg added 2/14/2010:

I did this, but never bothered to integrate it into a module. Also, we have a situation where, depending on patron type, certain users will have access to databases and others will not. Uses the III patron API class in the III locum connector which can be found at thesocialopac.net:

Config line:
::external=http://barnabas.darienlibrary.org/ezproxy/auth.php,post=user=^u&pass=^p,valid=+OK

auth.php:

<?php
require_once('MDB2.php');
require_once(
'/usr/local/etc/drupal_dsn.php');
require_once(
'/usr/local/lib/locum/connectors/locum_iii_2006/patronapi.php');

$user_table = 'shared_users';
$profile_table_f = 'darpl_profile_fields';
$profile_table_v = 'darpl_profile_values';
$verify_table = 'darpl_sopac_card_verify';
$valid_ptypes = array("0","2","6","8","10","12");
$iiiserver = 'pince.darienlibrary.org';


if (
$_POST[user] && $_POST[pass]) {
       
$db =& MDB2::connect($dsn);
       
$name = $db->quote($_POST[user]);
       
$pass = $db->quote($_POST[pass]);
       
$sql = "SELECT uid FROM $user_table WHERE name = $name AND pass = MD5($pass)";
       
$res =& $db->query("SELECT uid FROM $user_table WHERE name = $name AND pass = MD5($pass)");
       
$uid = $res->fetchOne();
} else {
        print
'+FAIL';
        exit;
}

if (
$uid) {
       
$res =& $db->query("SELECT fid FROM $profile_table_f WHERE name = 'profile_pref_cardnum'");
       
$cardnum_fid = $res->fetchOne();
       
$res =& $db->query("SELECT value FROM $profile_table_v JOIN $verify_table USING (uid) WHERE fid = $cardnum_fid AND uid = $uid AND
verified = 1"
);
       
$cardnum = $res->fetchOne();
} else {
        print
'+FAIL';
        exit;
}

if (
$cardnum) {
       
$patronapi = new iii_patronapi;
       
$patronapi->iiiserver = $iiiserver;
       
$userdata = $patronapi->get_patronapi_data($cardnum);
       
$ptype = (string) $userdata[PTYPE];
        if (
in_array($ptype, $valid_ptypes)) {
                print
'+OK';
        } else {
                print
'+FAIL';
        }
} else {
        print
'+FAIL';
        exit;
}

$db->disconnect();
?>

Libraries

Group organizers

Group categories

Resources

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: