login redirector plugin

login_redirector plugin by Christopher Smith
Redirect the login button to another URL

Provides Action.
Compatible with DokuWiki rc2006-09-28+.

Tagged with authentication, gui, login, redirect.

This plugin redirects the DokuWiki login button to another URL. It is most useful when combined with an external authentication method and it can direct the user to the common login page used by that method.

Notes

Acknowledgements

Configuration

setting default value description
url empty string* url of the external login page

If the url setting is empty, no redirection occurs and the normal DokuWiki login page will be shown.

Installation

This plugin can be installed by the plugin manager using the following packages:

Or using darcs

To install the plugin manually, download the source to your plugin folder, lib/plugins and extract its contents. That will create a new plugin folder, lib/plugins/loginredirect, and install the plugin.

The folder will contain:

action.php                             the plugin script
conf/default.php                       default configuration settings
conf/metadata.php                      information for DokuWiki's configuration page

The plugin is now installed.

Details

The plugin consists of one main files, the plugin script action.php and two other files to define the configuration setting for DokuWiki's Admin / Configuration page.

action.php

This is the code for the release version of DokuWiki. Users of the development version of DokuWiki should get the source from the darcs repository, either through darcs or through the web browser interface.

<?php
/**
 * Action Plugin:   Redirect login, for use with external auth methods
 * 
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Christopher Smith <chris@jalakai.co.uk>  
 */
 
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
 
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'action.php');
 
/**
 * All DokuWiki action plugins need to inherit from this class
 */
class action_plugin_loginredirect extends DokuWiki_Action_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
      return array(
        'author' => 'Christopher Smith',
        'email'  => 'chris@jalakai.co.uk',
        'date'   => '2006-10-14',
        'name'   => 'Login Redirector',
        'desc'   => 'Redirect a login request to another url, for use with external authentication methods.',
        'url'    => 'http://wiki.splitbrain.org/plugin:login_redirector',
      );
    }
 
    /*
     * plugin should use this method to register its handlers with the dokuwiki's event controller
     */
    function register(&$controller) {
      $controller->register_hook('ACTION_ACT_PREPROCESS','BEFORE', $this, 'handle_loginredirect');
    }
 
    function handle_loginredirect(&$event, $param) {
      if ($event->data == 'login') {
        $url = $this->getConf('url');
        if (empty($url)) return;
 
        header("Location: $url");
        exit();
      }
    }
 
 
}
 
//Setup VIM: ex: et ts=4 enc=utf-8 :

Revision History

  • 2006-12-22 — (darcs version only) Add ability to supply return URL
  • 2006-10-14 — Released.

To Do

  • add register redirect functionality, see discussion.

Bugs

Discussion

I've had no luck at getting this plug-in to work. I have installed the files within the plugin directory, specified the URL in default.php. I am missing something big here, and I can't figure out what. The login still goes to the default login page. I am running the released version of Doku and am using your zipped version of the plug-in, which I installed manually. I wish that I could give you more information about its behavior, but it's not doing anything to describe. I think I'm not putting the appropriate data in the metadata.php file. Could you describe, in further detail, what is required for metadata.php or give me some other pointers? –Pete

Do you have a link? When you say “the released version of Doku” do you mean one of the recent release candidates or the current release (2006-03-09e)? As mentioned at the very top of the page, the plugin requires rc2006-09-28 or later. Action plugins are not supported in 2006-03-09e (and earlier). — Christopher Smith 2006-10-21 20:51

My Doku installation wasn't as current as I thought. I have it working now. Thanks for you response! Could this concept also be applied to the registering process? It would be great if you could be redirected to a page to register and then brought back whence you came. –Pete


This plugin is (as far as I can see) incomplete. Every such third party authorization (Single Sign on) scheme relies on setting a cookie which can then be validated and used for authenticating the user. There should be a custom authentication class which checks the received signon cookie, validates the hash, sets the user, password, groups field (at the minimum) so that things like ACL could be implemented. Similarly, for logging a user out also needs to be implemented here. I have just finished writing custom authentication class and will clean it up and post it here for others…

Amit Chakradeo

Amit, your point is valid - this plugin requires a custom authentication mechanism to be of use. However, that is not the point of the plugin. If you are using an external login page, that page is most likely to set its own parameters for authentication and so each could well require its own authentication class. Also plugins by themselves can not influence authentication. There are no events surrounding authentication and I doubt any will be implemented. The plugin fills a gap whereby a “trust external” auth mechanism was unable to access the trusted external login page. — Christopher Smith 2006-11-03 20:44

It would be helpful to be able to append a return ID to the URL. If someone clicks the login button on a page buried:within:several:namespaces: it may be hard to navigate back to the page they wanted to edit.
I recommend adding configuration settings append_redir (onoff) and append_redir_key (string) so that $url would have ?key=value where value is either the ID (normalized to match current setting regarding url rewrites, etc) or a full URI. — Matt Ezell 2006-12-22 02:16

Hi Matt. Good idea and pretty straight forward to implement. I don't think there is any need for the append_redir setting. If the redir_key is present append it along with return url. If its not present, don't append anything. Does the value need to be encoded? — Christopher Smith 2006-12-22 18:34
I have implemented it for my custom login method, but I'm sending an ID and then redirecting to ../$_GET['ID']. I'm still too new to DW to know the best way to construct a URL based on the current page (because there are several different ways it may be constructed). I suppose you could just use the current URI and do a s/&+do=login//
You probably would need to run it through urlencode() but some testing would be necessary. Thanks!
Matt Ezell 2006-12-23 02:08

I would like a register redirector behaviour instead. I'm using the punbb authentication. I prefer login to use the ordinary dokuwiki form since you get back to the same page after login, but i'd prefer the external register page (i.e. that of punbb).

To turn this plugin into a register redirector plugin, just replace login with register, right? (Yes it is, I tried it!)

Viktor Söderqvist 2007-04-05 18:57

But it would be much better to add register redirect functionality to this same plugin. To do so, apply these changes:

In the end of function handle_loginredirect, add

      else if ($event->data == 'register') {
        $url = $this->getConf('url_register');
        if (empty($url)) return;
 
        header("Location: $url");
        exit();
      }

to settings/default.php add

$conf['url_register'] = '';               // location for register redirects

and to settings/metadata.php add

$meta['url_register'] = array('string');   // location for register redirects

Viktor Söderqvist 2007-04-05 20:52

 
plugin/login_redirector.txt · Last modified: 2008/03/06 17:59 by grahack
 
Imprint Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsTranslate