Hola,

I'm a semi noob to drupal, and have been hacking away all day trying to get this to work. I am trying to integrate drupal into my web app, and want the authentication to be passed by my app. It's a php app (PHP v.5) and uses a MySQL (MySQL v.5) database. I'm running linux, and lighttpd. Both drupal and my app are on the same DB server. I'm using PEAR::Auth in my web app's authentication scheme. I'd like to pass a username and password to drupal upon login (modifications to the current auth system aren't possible) and have the drupal session created. I assumed that I could use the {authmap} table to map my web app users to uid's in drupal. I have an entry for my user in there, setting 'user' as the module.

I think I'm close, but am missing a major part (maybe some sort of session_start() function)? I've gotten it to a point where user_external_load() returns the correct values, but I'm missing that last step. I've searched for single sign on solutions, and looked at many tutorials, but haven't found anything that accurately describes how the drupal authentication scheme works, or which functions are needed to establish a session.

Here's my proof of concept code:

<?php 
set_time_limit(0); //no timeouts
error_reporting(E_ALL);
$start = time();

ob_implicit_flush(true);
set_time_limit(0);
ini_set('memory_limit', '512M');

require_once('config.php');
require_once('../functions.php');
require_once('DB.php');
require_once('../classes/DataObject.php');
require_once('./modules/user/user.module');
require_once('./modules/filter/filter.module');
require_once './includes/bootstrap.inc';
require_once './includes/module.inc';
require_once './includes/common.inc';
require_once './includes/path.inc';
require_once './includes/theme.inc';
require_once './includes/session.inc';

drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
    
$db = DB::connect(MYSQL_DSN);
$db->setFetchMode(DB_FETCHMODE_ASSOC);
    
DB_DataObject::debugLevel(5);

$sql = "SELECT user from users WHERE username = 'test'"; 

echo "Logging in - ";echo date(DATE_RFC822);echo "<br />";

$loginAuth = $db->getOne($sql);
echo "<br>got result - authname: ";echo $loginAuth;
    
$my_login = user_external_load($loginAuth);
    
echo "<br>drupal returns: ";print_r($my_login);

//this doesn't work either!
//$user = user_authenticate('user', 'password');
//user_login();
//$drupal_auth = user_authenticate($my_login->name, $my_login->pass);

//stole this code from some ldap integration module
//User exists in database.  Set user info from there.
$user_name = $sf_login->name;
$user_number = $sf_login->uid;

//Log in, updating logs and redirecting to where the user requested, or home. Good stuff stolen from persistent login module.
drupal_set_message(t('Authenticated.  Welcome %name.', array('%name' => check_plain($user_name))));
$l = array('sf_auth_login' => 1,'name' => $user_name,'uid' => $user_number);
drupal_load('module', 'user');
$user = user_load(array('uid' => $l['uid']));
user_login_submit('my_auth_login',$l);
//drupal_goto('/?q=books');

//echo "<br>got past user_auth: ";    
?>

Any help or pointing in the right direction is much appreciated.

Thanks,

-ryan

Comments

rtwheato’s picture

just my own follow up since i'm not sure anyone even looked at this post... maybe my approach/solution will save others some time in the future.

i was able to accomplish my integration / single sign on by taking the httpauth module and using parts of it to suit my needs.

thanks?

-r