DokuWiki

It's better when it's simple

User Tools

Site Tools


auth:xmpp

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
auth:xmpp [2009-02-17 23:46] – added alternate code as original didn't work for me 92.237.80.58auth:xmpp [2010-09-02 09:09] (current) – old revision restored mluigi
Line 1: Line 1:
 +====== XMPP/Jabber authentication  ======
  
 +===== Incompatibility with the current version of DokuWiki =====
 +
 +  * Tried to use both variants on DokuWiki version 2009-12-25c "Lemming". Both rendered my wiki inaccessible with "Bad user authentication configuration. Please inform your Wiki Admin."  --- //lolmaus 2010/02/17 18:58//
 +
 +===== What does it do? =====
 +
 +It authenticates users by logging into an XMPP server. This was originally conceived in order to have a website authenticate against email accounts set up on Gmail for a whole domain. It's really incomplete and "hacky."
 +
 +===== Requirements =====
 +
 +  * XMPPHP (http://code.google.com/p/xmpphp/)
 +
 +===== Installation =====
 +
 +Paste the code into "inc/auth/xmpp.php", then add the following line to "conf/local.php":
 +
 +  $conf['authtype'] = 'xmpp';
 +
 +And remember to alter "xmpp.php", so that it suits your configuration.
 +
 +===== Code =====
 +
 +<code php>
 +<?php
 +/**
 + * XMPP/Jabber authentication backend
 + *
 + * http://www.dokuwiki.org/auth:xmpp
 + *
 + * XMPPHP from http://code.google.com/p/xmpphp/ under 'XMPPHP' dir is needed
 + * for this to work at all.
 + *
 + * @license    GPL 2 or any later version (http://www.gnu.org/licenses/gpl.html)
 + * @author     Mariusz Mazur <mmazur@kernel.pl>
 + */
 +
 +include 'XMPPHP/XMPP.php';
 +
 +$server = 'talk.google.com';
 +$port = 5222;
 +$domain = 'radioemiter.pl';
 +
 +// we only accept page ids for auth_plain
 +if(isset($_REQUEST['u']))
 +        $_REQUEST['u'] = cleanID($_REQUEST['u']);
 +
 +/**
 + * Check user+password [required auth function]
 + *
 + * Checks if the given user exists and the given
 + * plaintext password is correct by trying to
 + * connect to and authenticate against an xmpp
 + * server.
 + *
 + * @author  Mariusz Mazur <mmazur@kernel.pl>
 + * @return  bool
 + */
 +function auth_checkPass($user,$pass){
 +  global $server;
 +  global $port;
 +  global $domain;
 +
 +  $conn = new XMPPHP_XMPP($server, $port, $user, $pass, 'dokuwiki', $domain, $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO);
 +
 +  try {
 +    $conn->connect();
 +    $conn->processUntil('session_start');
 +    $conn->disconnect();
 +    return true;
 +  } catch(XMPPHP_Exception $e) {
 +    return false;
 +  }
 +}
 +
 +/**
 + * Return user info [required auth function]
 + *
 + * Returns info about the given user needs to contain
 + * at least these fields:
 + *
 + * name string  full name of the user
 + * mail string  email address of the user
 + * grps array   list of groups the user is in
 + *
 + * No group support yet.
 + *
 + * @author  Mariusz Mazur <mmazur@kernel.pl>
 + */
 +function auth_getUserData($user){
 +  $userinfo = array ("name" => $user, "mail" => "$user@$domain", "grps" => array ("user", "editors"));
 +  return $userinfo;
 +}
 +
 +/**
 + * Create a new User [required auth function]
 + *
 + * Returns false if the user already exists, null when an error
 + * occurred and the cleartext password of the new user if
 + * everything went well.
 + *
 + * This obviously always returns null, since sane admins
 + * have account creation disabled on XMPP servers.
 + *
 + * @author  Mariusz Mazur <mmazur@kernel.pl>
 + */
 +function auth_createUser($user,$pass,$name,$mail){
 +  msg('User account creation is unavailable..',-1);
 +  return null;
 +}
 +
 +//Setup VIM: ex: et ts=2 enc=utf-8 :
 +
 +</code>
 +
 +===== Alternate Code =====
 +
 +The above doesn't work for me, I don't know if the way DokuWiki works has changed since it was written as I'm a first time user (above doesn't use class). The code below 'works' for me, same warnings as above really its a total hack and has very minimal functionality YMMV.
 +
 +<code php>
 +<?php
 +/**
 + * XMPP/Jabber authentication backend
 + *
 + * http://www.dokuwiki.org/auth:xmpp
 + *
 + * XMPPHP from http://code.google.com/p/xmpphp/ under 'XMPPHP' dir is needed
 + * for this to work at all.
 + *
 + * @license    GPL 2 or any later version (http://www.gnu.org/licenses/gpl.html)
 + * @author     Matthias Grimm <matthiasgrimm@users.sourceforge.net>
 + * @author     Mariusz Mazur <mmazur@kernel.pl>
 + * @author     Andreas Gohr <andi@splitbrain.org>
 + * @author     Paul Thomas <doku@paulthomas.eu>
 + */
 +
 +define('DOKU_AUTH', dirname(__FILE__));
 +require_once(DOKU_AUTH.'/basic.class.php');
 +
 +require_once("/XMPPHP/XMPP.php");
 +
 +class auth_xmpp extends auth_basic {
 +
 +        var $server = "jabber.org";
 +        var $port = 5222;
 +        var $domain = "jabberd.org";
 +
 +    /**
 +     * Constructor
 +     *
 +     * checks if the MySQL interface is available, otherwise it will
 +     * set the variable $success of the basis class to false
 +     *
 +     * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
 +     * @author Paul Thomas <doku@paulthomas.eu>
 +     */
 +    function auth_xmpp() {
 +        global $conf;
 +        if (method_exists($this, 'auth_basic'))
 +                parent::auth_basic();
 +
 +    }
 +    /**
 +     * Checks if the given user exists and the given plaintext password
 +     * is correct. Further on, it might be checked whether the user is
 +     * member of the right group
 +     *
 +     * Depending on which SQL string is defined in the config, password
 +     * checking is done here (getpass) or by the database (passcheck)
 +     *
 +     * @param  $user  user who would like access
 +     * @param  $pass  user's clear text password to check
 +     * @return bool
 +     *
 +     * @author  Andreas Gohr <andi@splitbrain.org>
 +     * @author  Matthias Grimm <matthiasgrimm@users.sourceforge.net>
 +     * @author  Paul Thomas <doku@paulthomas.eu>
 +     */
 +    function checkPass($user,$pass){
 +        $conn = new XMPPHP_XMPP($this->server, $this->port, $user, $pass, "dokuwiki", $this->domain, $printlog=false, $loglevel=XMPPHP_Log::LEVEL_ERROR);
 +
 +        try {
 +                $conn->connect();
 +                $conn->processUntil('session_start');
 +                $conn->disconnect();
 +                $this->success = true;
 +                return true;
 +        }
 +        catch (XMPPHP_Exception $e) {
 +                $this->success = false;
 +                return false;
 +        }
 +        return false;
 +    }
 +
 +        function getUserData($user){
 +                $userinfo = array ("name" => $user, "mail" => "$user@$domain", "grps" => array ("user", "editors", "admin"));
 +                return $userinfo;
 +        }
 +}
 +
 +</code>
auth/xmpp.txt · Last modified: 2010-09-02 09:09 by mluigi

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki