Writings Photos Code Contact Resume
Drupal authentication backend for dokuwiki.

You are here

Submitted by msameer on Tue, 13/12/2005 - 10:41am
This authentication backend'll enable your DokuWiki to authenticate using the drupal database.
This code is pulled from my svn which means that whenever I update it, It'll reflect the file displayed here ;-)
Or get the file directly from here.
Can't open the file!

Comments

Submitted by Mostafa Hussein (not verified) on Sun, 18/12/2005 - 10:46pm

Ok, how do I get this to work ?

Submitted by Alexa (not verified) on Mon, 24/04/2006 - 6:39am

I have the same question like that of Mostafa:

How to make this script work? And where to put it?

Thanks for help.

Submitted by msameer on Tue, 25/04/2006 - 9:32pm

Are you sure you had a look at the dokuwiki authentication manual ?

I'm out of Cairo ATM, Sorry I can't provide more help.

Submitted by Matthew Robinson (not verified) on Wed, 23/08/2006 - 8:23pm

The first mysql_fetch_row() in getUserData() should be replaced with

<?php
 
if (! $tmp = mysql_fetch_row($result)) {
    return
false;
  }
?>

You'l also need to change the first query in getUserData() to include

AND pass='$pass'

This will provide some error checking, and the function will also double password checker, removing the need for 2 db queries.

Submitted by msameer on Wed, 23/08/2006 - 9:30pm

Thanks Matthew.

I'm now checking that we are getting results in getUserData()

But do you think that checking the user password is really needed ?

Submitted by Matthew Robinson (not verified) on Thu, 24/08/2006 - 9:46am

Well it makes the getUserData() double as an authentication function, reducing the amount of database queries and making the code easier to read. I dont have a clue about any of your other code (I accidentily stumbled accross this page), but you could possibly rename the function to login, and do something like:

$_SESSION = login($username,$password)

or similar.

then $_SESSION is either false (not logged in) or is populated with the array(?) passed back from the getUserData function (or login if you decide to rename it)

Submitted by msameer on Fri, 25/08/2006 - 10:14am

I can't really rename the function because this is how the dokuwiki authentication works.

Well, I can get all the variables I need using 1 query in the constructor and the other functions will just return them. It just needs a rewrite ;)

Submitted by alienbrain on Wed, 30/08/2006 - 2:06pm

In TODO there is "Groups with spaces'll screw us."
For this, I had to change:
$info['grps'][] = $tmp[0];
to:
$info['grps'][] = str_replace(' ', '_', $tmp[0]);
to be able to use something like @authenticated_user in acl.

Also, I've a suggestion, I think this backend should also check if the user is blocked or not.

Submitted by msameer on Wed, 30/08/2006 - 4:52pm

I'm now checking that the user is active. Thanks for the note.

I don't like replacing the spaces with underscores. What if I have an identical group but with underscores ?

Submitted by Alessio (not verified) on Wed, 11/10/2006 - 9:59am

I have a drupal site, www.theeyes.org and a wiki, creta.theeyes.org
I tried to make the script working, without success.
The question is: where does the backend take the $drupal_file?
I see the lines:

$drupal_file = $conf['auth']['drupal']['file'];
include ($drupal_file);

I imagine $drupal_file is the settings.php, but where does the script look for this file? I have it in www.theeyes.org/sites/theeyes.org/settings.php.
I tried to copy it in creta.theeyes.org/sites/theeyes.org/settings.php or to set the docroot for creta insiede the drupal site, so now i have the wiki in creta.theeyes.org and www.theeyes.org/creta. But again, the wiki can't connect to mysql server. Any ideas?

Sorry for my bad english...

Submitted by msameer on Fri, 13/10/2006 - 9:54pm

You set $conf['auth']['drupal']['file'] in local.php

$conf['auth']['drupal']['file'] should point to the location of the file on the server. For me I have it set to:

$conf['auth']['drupal']['file'] = "/home/vhosts/foolab.org/www/sites/default/settings.php";

And don't forget to set authtype

$conf['authtype']    = 'drupal';
Submitted by Alessio (not verified) on Sat, 14/10/2006 - 6:40am

Thank you,
now it works :)

Now I try to use the same cookie for dokuwiki and drupal, if I have fortune, I'll post a comment here ;)

Thanks again!

Submitted by Christopher R. Parr (not verified) on Fri, 22/12/2006 - 1:13pm

Hi!

In principle the authentification works. But when I login with the drupal admin user, that user is not admin in dokuwiki. How can this be fixed?

Thanks.

Christopher

Submitted by msameer on Fri, 22/12/2006 - 10:58pm

What you need to do is to set that user as the dokuwiki admin:

$conf['superuser']   = 'msameer';    //The admin can be user or @group

in local.php

I'm planning for more integration between drupal and dokuwiki but I have no time to really work on it.

Submitted by Driadan (not verified) on Fri, 05/01/2007 - 9:20pm

Hi, I tried to use your auth method, but it didnt work.
I'm using
- dokuwiki-2006-11-06
- drupal 4.7.4
- mysql (I believe its version 4)
- php (both 4 and 5 are installed)

The mysql database and the webserver are in different machines.
I'm using a hosting service, so i can't run commands, but i can ask them whatever you need to know.

The error i have:

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in -path_to_wiki-/inc/auth/drupal.class.php on line 43

Could not connect: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

I have created the drupal.class.php file and filled the $conf['auth']['drupal']['file'] in the local.php file.

I have searched around and it says it has to do with either the mysql service being down (which it isn't, since i can log in to drupal), or a missconfiguration.

I know a bit of programming, but i dont know either php or sql, so i'm not sure where to modify. It may be because of the db being in a sepparate machine? I'm missing something?

Thanks a lot for your time and for contributing this code.

Submitted by msameer on Sat, 06/01/2007 - 1:09am

Are you sure that the path to the file is correct ?

Submitted by Driadan (not verified) on Sat, 06/01/2007 - 4:42pm

Damn, a "t" in settings, I swear i doublechecked it.

I'm really sorry for having such a little thing take.

Thanks a lot.

Submitted by msameer on Sat, 06/01/2007 - 5:47pm

Congratulations for the site :-)

Cheers.

Submitted by Walter G. (not verified) on Sun, 28/01/2007 - 10:57pm

Hi Mohammed,

I just started using your Drupal auth for dokuwiki, and ran into a problem. Namely, my DB password was in the form "a+password," which Drupal stores as "a%2Bpassword." To fix this, I added the following code before making the MySQL connection.

<?php
   
//Adapted from the Drupal database.mysql.inc code
    //Decode url-encoded information in the db connection string
   
$this->url['user'] = urldecode($this->url['user']);
   
// Test if database url has a password.
   
if(isset($this->url['pass'])) {
     
$this->url['pass'] = urldecode($this->url['pass']);
    } else {
     
$this->url['pass'] = '';
    }

   
$this->url['host'] = urldecode($this->url['host']);
   
$this->url['path'] = urldecode($this->url['path']);
?>

Hope this is useful!

Walter

Submitted by msameer on Sun, 28/01/2007 - 11:40pm

Thanks. I've added the snippet!

Submitted by John (not verified) on Sun, 25/03/2007 - 8:37pm

Hi - I'm getting these two error messages in Dokuwiki:

Can't select the database: No database selected
User authentication is temporarily unavailable. If this situation persists, please inform your Wiki Admin.

Here is my local.php (conf directory)

<?php
$conf['title'] = 'mysite';
$conf['lang'] = 'en';
$conf['useacl'] = 1;
$conf['superuser'] = '@admin';
$conf['authtype'] = 'drupal';
$conf['auth']['drupal']['file'] = "/drupal-5.1/sites/default/settings.php";

I created drupal.class.php in the inc\auth directory, using Mohammed's code above.

I must be forgetting something easy!

Submitted by msameer on Mon, 26/03/2007 - 4:36pm

Drupal can connect but dokuwiki can't ?

Do you have non alphanumeric charcters in the database name or the username or the password ?

Submitted by John (not verified) on Sat, 31/03/2007 - 12:41am

Here is my database name from my settings.php file...
$db_url = 'mysql://mysite:db405is@localhost/mysitedrupal';

Could this be the problem?

Submitted by msameer on Sat, 31/03/2007 - 6:09pm

That shouldn't be a problem.

The only thing that I can think of is the path to the drupal settings.php

Submitted by Zebra (not verified) on Mon, 07/05/2007 - 2:58pm

I'm planning to use IMAP authentication on Drupal and have Doku authenticate against the Drupal Database.

Hope it works. :)

Username logins will be name@domain.com + password

Submitted by msameer on Mon, 07/05/2007 - 4:36pm

It will work if the usernames and passwords are in the drupal database

Submitted by Anonymous (not verified) on Wed, 23/05/2007 - 6:33pm

Where's the file? cvs is 404 and the node says "can't open the file!". *shrugs*

Submitted by msameer on Wed, 23/05/2007 - 8:31pm

Sorry. I moved to subversion and forgot to update this. Fixed. Sorry!

Submitted by David Ing (not verified) on Thu, 14/06/2007 - 5:20pm

The "Edit this page" and "Login" buttons still show up in Dokuwiki after I've followed the above instructions.

I'm at Dokuwiki release 2006-11-06 and Drupal v.5.1 . I've copied the above text as drupal.class.php into inc/auth . I've configured the database string so that I don't get the "Can't select the database: No database selected" message any more.

Can you help me figure out what I'm missing?

In local.php, I have:

/* Authentication Options */
$conf['useacl']  = 1;
$conf['openregister']= 0;
$conf['superuser']  = '@admin'; 
$conf['authtype']    = 'drupal';
$conf['auth']['drupal']['file'] = "/home/web/mywebsite/drupal/sites/default/settings.php";

If I run doku.php?do=check, I get:

DokuWiki version: Release 2006-11-06
PHP version 5.2.1
Changelog is writable
Datadir is writable
Attic is writable
Mediadir is writable
Cachedir is writable
Lockdir is writable
conf/users.auth.php is writable
mb_string extension is available and will be used
Debugging support is disabled
Your current permission for this page is 4
The current page is writable by the webserver
The current page is writable by you

I've logged out of Drupal on Firefox and closed the browser, to get the same effect. On IE, there's a message about "Done, with errors on page", but I don't know how to check those errors.

I seem so close ... and yet so far away! Thanks.

Submitted by msameer on Thu, 14/06/2007 - 8:52pm

What's in your conf/acl.auth.php ?

Mine has:

# acl.auth.php
# <?php exit()?>
# Don't modify the lines above
#
# Access Control
#
# none   0
# read   1
# edit   2
# create 4
# upload 8

*               @ALL        1

Thanks for telling me about the new dokuwiki release. I updated mine :-)

Submitted by daviding on Fri, 15/06/2007 - 3:58am

My acl.auth.php had @ALL 4. I copied yours. The button immediately changed from "Edit this page" to "Show pagesource". That's progress. Thanks for that help.

When I fill in the login screens on Dokuwiki with the Drupal userid and password, my userid shows up at the bottom of the page. However, the "Show pagesource" button remains.

My colleague has pointed out that in dokuwiki.php , we have the following settings:

/* Authentication Options - read http://www.splitbrain.org/dokuwiki/wiki:acl */

$conf['useacl']      = 0;                //Use Access Control Lists to restrict access?
$conf['autopasswd']  = 1;                //autogenerate passwords and email them to user
$conf['authtype']    = 'plain';          //which authentication backend should be used
$conf['passcrypt']   = 'smd5';           //Used crypt method (smd5,md5,sha1,ssha,crypt,mysql,my411)
$conf['defaultgroup']= 'user';           //Default groups new Users are added to
$conf['superuser']   = '!!not set!!';    //The admin can be user or @group
$conf['profileconfirm'] = '1';           //Require current password to confirm changes to user profile
$conf['disableactions'] = '';            //comma separated list of actions to disable

What do you have in your dokuwiki.php ? (I don't know why this content seems redundant. Does local.php take precedence?)

Submitted by msameer on Fri, 15/06/2007 - 7:10am

Yup, local.php takes precedence

I guess you need to set the ACLs for group admin and add the user you ar using there.

For me, I have only one user who is allowed to edit thus:

$conf['superuser']   = 'msameer';

in local.conf

Submitted by daviding on Fri, 15/06/2007 - 9:40am

Thanks for the help. I've changed the superuser from @group to the single admin id. When I log into Dokuwiki now, the "Edit this page" has come back.

When I try with my regular userid, though -- we have multiple userids in Drupal defined with "administrator" privileges -- I don't get the "Edit this page".

How do you give Dokuwiki editing privileges to specific Drupal userids? Is this done in Dokuwiki or in Drupal?

Submitted by msameer on Fri, 15/06/2007 - 12:34pm

You assign them to a certain drupal group, then you set the dokuwiki proper ACLs for that group.

I didn't really do a setup like this as I didn't need it.

I guess you need to check the documentation for dokuwiki on how to setup ACLs for groups.

Glad it worked for you!

Submitted by Anonymous (not verified) on Fri, 29/06/2007 - 12:34am
[Thu Jun 28 19:15:11 2007] [error] [client 192.168.1.4] PHP Warning:  parse_url
() expects parameter 1 to be string, array given in /var/www/wiki/inc/auth/
drupal.class.php on line 40, referer: http://example.com/wiki/doku.php/aimb
ot

Ideas?

Submitted by msameer on Fri, 29/06/2007 - 9:24am

is $db_url an array ?

I fixed this situation. Now $db_url['default'] will be used if $db_url is an array. I didn't test it yet.

Submitted by Anonymous (not verified) on Wed, 04/07/2007 - 9:39pm

In this brief blog entry I'll explain how to install dokuwiki with drupal authentication.

So you have Drupal installed and your user account already established. Next install dokuwiki. Once that's done we now append the rewrite prefs for the clean .htaccess style clean-urls. Add to /etc/httpd/conf/httpd.conf (assumes directory = /var/www/html/wiki and Drupal is installed at /var/www/html/*). Read more...

Submitted by Anonymous (not verified) on Thu, 02/08/2007 - 1:54pm

Broken w/ Drupal v5.2? Worked just fine and then *poof*.

Submitted by msameer on Thu, 02/08/2007 - 8:51pm

What's broken ? I'm running 5.2

Submitted by Alex (not verified) on Sun, 24/02/2008 - 6:54am

My v5.2 is broken also. any news on a fix ?

Submitted by msameer on Mon, 25/02/2008 - 1:38am

What do you mean by broken ?

Submitted by Chris (not verified) on Wed, 17/09/2008 - 12:33pm

Hi, is there a way to use this code in Drupal 6.4? Please let me know if you have any experience.

Submitted by msameer on Wed, 17/09/2008 - 9:55pm

Try it.

I didn't move to 6.4 yet so I don't really know.

Submitted by Chris (not verified) on Thu, 18/09/2008 - 6:30am

Hi, I tried it. I get this error message (when browsing to: localhost:8800 (->dokuwiki)):
"DokuWiki Setup Error

Bad user authentication configuration. Please inform your Wiki Admin."

I have Drupal 6.4 in the Xamp(newest ver.) folder. Dokuwiki (on a stick) is in the Drupal folder.

I was using these instructions:
http://www.coalface.net/node/22

So, I named your php script to: drupal_ext.class.php

"# Add the drupal_ext.class.php file to your /auth directory
# Register the Drupal auth method with Dokuwiki

1. From the Dokuwiki configuration page (Admin > Configuration Settings), select "drupal_ext" next to "Authentication backend."

This was somewhat encouraging at least as I only got an error message on line 114 with that php-script coalface provided.

Any ideas? I'm a beginner but eager to get this to work.

Best regards,
Chris

Submitted by msameer on Thu, 18/09/2008 - 10:09am

Please use the instructions from here: http://foolab.org/node/785#comment-16489

Submitted by Crisd (not verified) on Fri, 13/03/2009 - 11:27pm

Thanks for the help. I've changed the superuser from @group to the single admin id. When I log into Dokuwiki now, the "Edit this page" has come back.

When I try with my regular userid, though -- we have multiple userids in Drupal defined with "administrator" privileges -- I don't get the "Edit this page". muhabbet
Sohbet
How do you give Dokuwiki editing privileges to specific Drupal userids? Is this done in Dokuwiki or in Drupal?

Submitted by msameer on Sun, 15/03/2009 - 4:54pm

I think you do it in dokuwiki.

Add new comment

Subscribe to /  digg  bookmark