Jump to content

Adding a custom authentication module

From NusaATK
Revision as of 15:10, 3 September 2008 by Lorna (talk | contribs) (Creating the page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

ATK Howto: Adding a custom authentication module

Complexity: Advanced
Author: Lorna Mitchell <lorna@ibuildings.com>

List of other Howto's

There are a number of different security modules available in atk - you can find them atk/security. We can easily add another, for example I added one to authenticate against a REST service. They all extend the class auth_interface, so this is a good place to start. My REST class looked a bit like this:

   class auth_rest extends auth_interface
   {
     var $m_rightscache = array();

     function validateUser($user, $passwd)
     {
       if ($user=="") return AUTH_UNVERIFIED; // can't verify if we have no userid

       $attr = < the attributes of the result of the call to the REST service >
       if($attr['status'] == 'ok') {
           return AUTH_SUCCESS;
       } elseif ($attr['status'] == 'error') {
           $error_attr = $xml->error->attributes();
           if($error_attr['code'] == 'LoginError') {
               return AUTH_UNVERIFIED;
           } elseif($error_attr['code'] == 'BlockedUserError') {
               return AUTH_LOCKED;
           }

       }

     }

     function canMd5()
     {
       return false;
     }

   }

To use this class, the $config_authentication variable needs to be set to match the new class you made. To use the example above we can do:

  $config_authentication = "rest";