1*80852c15SAndreas Gohr<?php 2*80852c15SAndreas Gohr/** 3*80852c15SAndreas Gohr * DokuWiki Plugin oauth (Auth Component) 4*80852c15SAndreas Gohr * 5*80852c15SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6*80852c15SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 7*80852c15SAndreas Gohr */ 8*80852c15SAndreas Gohr 9*80852c15SAndreas Gohr// must be run within Dokuwiki 10*80852c15SAndreas Gohrif(!defined('DOKU_INC')) die(); 11*80852c15SAndreas Gohr 12*80852c15SAndreas Gohrclass auth_plugin_oauth extends DokuWiki_Auth_Plugin { 13*80852c15SAndreas Gohr 14*80852c15SAndreas Gohr 15*80852c15SAndreas Gohr /** 16*80852c15SAndreas Gohr * Constructor. 17*80852c15SAndreas Gohr */ 18*80852c15SAndreas Gohr public function __construct() { 19*80852c15SAndreas Gohr parent::__construct(); // for compatibility 20*80852c15SAndreas Gohr 21*80852c15SAndreas Gohr // FIXME set capabilities accordingly 22*80852c15SAndreas Gohr //$this->cando['addUser'] = false; // can Users be created? 23*80852c15SAndreas Gohr //$this->cando['delUser'] = false; // can Users be deleted? 24*80852c15SAndreas Gohr //$this->cando['modLogin'] = false; // can login names be changed? 25*80852c15SAndreas Gohr //$this->cando['modPass'] = false; // can passwords be changed? 26*80852c15SAndreas Gohr //$this->cando['modName'] = false; // can real names be changed? 27*80852c15SAndreas Gohr //$this->cando['modMail'] = false; // can emails be changed? 28*80852c15SAndreas Gohr //$this->cando['modGroups'] = false; // can groups be changed? 29*80852c15SAndreas Gohr //$this->cando['getUsers'] = false; // can a (filtered) list of users be retrieved? 30*80852c15SAndreas Gohr //$this->cando['getUserCount']= false; // can the number of users be retrieved? 31*80852c15SAndreas Gohr //$this->cando['getGroups'] = false; // can a list of available groups be retrieved? 32*80852c15SAndreas Gohr //$this->cando['external'] = false; // does the module do external auth checking? 33*80852c15SAndreas Gohr //$this->cando['logout'] = true; // can the user logout again? (eg. not possible with HTTP auth) 34*80852c15SAndreas Gohr 35*80852c15SAndreas Gohr // FIXME intialize your auth system and set success to true, if successful 36*80852c15SAndreas Gohr $this->success = true; 37*80852c15SAndreas Gohr } 38*80852c15SAndreas Gohr 39*80852c15SAndreas Gohr 40*80852c15SAndreas Gohr /** 41*80852c15SAndreas Gohr * Log off the current user [ OPTIONAL ] 42*80852c15SAndreas Gohr */ 43*80852c15SAndreas Gohr //public function logOff() { 44*80852c15SAndreas Gohr //} 45*80852c15SAndreas Gohr 46*80852c15SAndreas Gohr /** 47*80852c15SAndreas Gohr * Do all authentication [ OPTIONAL ] 48*80852c15SAndreas Gohr * 49*80852c15SAndreas Gohr * @param string $user Username 50*80852c15SAndreas Gohr * @param string $pass Cleartext Password 51*80852c15SAndreas Gohr * @param bool $sticky Cookie should not expire 52*80852c15SAndreas Gohr * @return bool true on successful auth 53*80852c15SAndreas Gohr */ 54*80852c15SAndreas Gohr //public function trustExternal($user, $pass, $sticky = false) { 55*80852c15SAndreas Gohr /* some example: 56*80852c15SAndreas Gohr 57*80852c15SAndreas Gohr global $USERINFO; 58*80852c15SAndreas Gohr global $conf; 59*80852c15SAndreas Gohr $sticky ? $sticky = true : $sticky = false; //sanity check 60*80852c15SAndreas Gohr 61*80852c15SAndreas Gohr // do the checking here 62*80852c15SAndreas Gohr 63*80852c15SAndreas Gohr // set the globals if authed 64*80852c15SAndreas Gohr $USERINFO['name'] = 'FIXME'; 65*80852c15SAndreas Gohr $USERINFO['mail'] = 'FIXME'; 66*80852c15SAndreas Gohr $USERINFO['grps'] = array('FIXME'); 67*80852c15SAndreas Gohr $_SERVER['REMOTE_USER'] = $user; 68*80852c15SAndreas Gohr $_SESSION[DOKU_COOKIE]['auth']['user'] = $user; 69*80852c15SAndreas Gohr $_SESSION[DOKU_COOKIE]['auth']['pass'] = $pass; 70*80852c15SAndreas Gohr $_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO; 71*80852c15SAndreas Gohr return true; 72*80852c15SAndreas Gohr 73*80852c15SAndreas Gohr */ 74*80852c15SAndreas Gohr //} 75*80852c15SAndreas Gohr 76*80852c15SAndreas Gohr /** 77*80852c15SAndreas Gohr * Check user+password 78*80852c15SAndreas Gohr * 79*80852c15SAndreas Gohr * May be ommited if trustExternal is used. 80*80852c15SAndreas Gohr * 81*80852c15SAndreas Gohr * @param string $user the user name 82*80852c15SAndreas Gohr * @param string $pass the clear text password 83*80852c15SAndreas Gohr * @return bool 84*80852c15SAndreas Gohr */ 85*80852c15SAndreas Gohr public function checkPass($user, $pass) { 86*80852c15SAndreas Gohr // FIXME implement password check 87*80852c15SAndreas Gohr return false; // return true if okay 88*80852c15SAndreas Gohr } 89*80852c15SAndreas Gohr 90*80852c15SAndreas Gohr /** 91*80852c15SAndreas Gohr * Return user info 92*80852c15SAndreas Gohr * 93*80852c15SAndreas Gohr * Returns info about the given user needs to contain 94*80852c15SAndreas Gohr * at least these fields: 95*80852c15SAndreas Gohr * 96*80852c15SAndreas Gohr * name string full name of the user 97*80852c15SAndreas Gohr * mail string email addres of the user 98*80852c15SAndreas Gohr * grps array list of groups the user is in 99*80852c15SAndreas Gohr * 100*80852c15SAndreas Gohr * @param string $user the user name 101*80852c15SAndreas Gohr * @return array containing user data or false 102*80852c15SAndreas Gohr */ 103*80852c15SAndreas Gohr public function getUserData($user) { 104*80852c15SAndreas Gohr // FIXME implement 105*80852c15SAndreas Gohr return false; 106*80852c15SAndreas Gohr } 107*80852c15SAndreas Gohr 108*80852c15SAndreas Gohr /** 109*80852c15SAndreas Gohr * Create a new User [implement only where required/possible] 110*80852c15SAndreas Gohr * 111*80852c15SAndreas Gohr * Returns false if the user already exists, null when an error 112*80852c15SAndreas Gohr * occurred and true if everything went well. 113*80852c15SAndreas Gohr * 114*80852c15SAndreas Gohr * The new user HAS TO be added to the default group by this 115*80852c15SAndreas Gohr * function! 116*80852c15SAndreas Gohr * 117*80852c15SAndreas Gohr * Set addUser capability when implemented 118*80852c15SAndreas Gohr * 119*80852c15SAndreas Gohr * @param string $user 120*80852c15SAndreas Gohr * @param string $pass 121*80852c15SAndreas Gohr * @param string $name 122*80852c15SAndreas Gohr * @param string $mail 123*80852c15SAndreas Gohr * @param null|array $grps 124*80852c15SAndreas Gohr * @return bool|null 125*80852c15SAndreas Gohr */ 126*80852c15SAndreas Gohr //public function createUser($user, $pass, $name, $mail, $grps = null) { 127*80852c15SAndreas Gohr // FIXME implement 128*80852c15SAndreas Gohr // return null; 129*80852c15SAndreas Gohr //} 130*80852c15SAndreas Gohr 131*80852c15SAndreas Gohr /** 132*80852c15SAndreas Gohr * Modify user data [implement only where required/possible] 133*80852c15SAndreas Gohr * 134*80852c15SAndreas Gohr * Set the mod* capabilities according to the implemented features 135*80852c15SAndreas Gohr * 136*80852c15SAndreas Gohr * @param string $user nick of the user to be changed 137*80852c15SAndreas Gohr * @param array $changes array of field/value pairs to be changed (password will be clear text) 138*80852c15SAndreas Gohr * @return bool 139*80852c15SAndreas Gohr */ 140*80852c15SAndreas Gohr //public function modifyUser($user, $changes) { 141*80852c15SAndreas Gohr // FIXME implement 142*80852c15SAndreas Gohr // return false; 143*80852c15SAndreas Gohr //} 144*80852c15SAndreas Gohr 145*80852c15SAndreas Gohr /** 146*80852c15SAndreas Gohr * Delete one or more users [implement only where required/possible] 147*80852c15SAndreas Gohr * 148*80852c15SAndreas Gohr * Set delUser capability when implemented 149*80852c15SAndreas Gohr * 150*80852c15SAndreas Gohr * @param array $users 151*80852c15SAndreas Gohr * @return int number of users deleted 152*80852c15SAndreas Gohr */ 153*80852c15SAndreas Gohr //public function deleteUsers($users) { 154*80852c15SAndreas Gohr // FIXME implement 155*80852c15SAndreas Gohr // return false; 156*80852c15SAndreas Gohr //} 157*80852c15SAndreas Gohr 158*80852c15SAndreas Gohr /** 159*80852c15SAndreas Gohr * Bulk retrieval of user data [implement only where required/possible] 160*80852c15SAndreas Gohr * 161*80852c15SAndreas Gohr * Set getUsers capability when implemented 162*80852c15SAndreas Gohr * 163*80852c15SAndreas Gohr * @param int $start index of first user to be returned 164*80852c15SAndreas Gohr * @param int $limit max number of users to be returned 165*80852c15SAndreas Gohr * @param array $filter array of field/pattern pairs, null for no filter 166*80852c15SAndreas Gohr * @return array list of userinfo (refer getUserData for internal userinfo details) 167*80852c15SAndreas Gohr */ 168*80852c15SAndreas Gohr //public function retrieveUsers($start = 0, $limit = -1, $filter = null) { 169*80852c15SAndreas Gohr // FIXME implement 170*80852c15SAndreas Gohr // return array(); 171*80852c15SAndreas Gohr //} 172*80852c15SAndreas Gohr 173*80852c15SAndreas Gohr /** 174*80852c15SAndreas Gohr * Return a count of the number of user which meet $filter criteria 175*80852c15SAndreas Gohr * [should be implemented whenever retrieveUsers is implemented] 176*80852c15SAndreas Gohr * 177*80852c15SAndreas Gohr * Set getUserCount capability when implemented 178*80852c15SAndreas Gohr * 179*80852c15SAndreas Gohr * @param array $filter array of field/pattern pairs, empty array for no filter 180*80852c15SAndreas Gohr * @return int 181*80852c15SAndreas Gohr */ 182*80852c15SAndreas Gohr //public function getUserCount($filter = array()) { 183*80852c15SAndreas Gohr // FIXME implement 184*80852c15SAndreas Gohr // return 0; 185*80852c15SAndreas Gohr //} 186*80852c15SAndreas Gohr 187*80852c15SAndreas Gohr /** 188*80852c15SAndreas Gohr * Define a group [implement only where required/possible] 189*80852c15SAndreas Gohr * 190*80852c15SAndreas Gohr * Set addGroup capability when implemented 191*80852c15SAndreas Gohr * 192*80852c15SAndreas Gohr * @param string $group 193*80852c15SAndreas Gohr * @return bool 194*80852c15SAndreas Gohr */ 195*80852c15SAndreas Gohr //public function addGroup($group) { 196*80852c15SAndreas Gohr // FIXME implement 197*80852c15SAndreas Gohr // return false; 198*80852c15SAndreas Gohr //} 199*80852c15SAndreas Gohr 200*80852c15SAndreas Gohr /** 201*80852c15SAndreas Gohr * Retrieve groups [implement only where required/possible] 202*80852c15SAndreas Gohr * 203*80852c15SAndreas Gohr * Set getGroups capability when implemented 204*80852c15SAndreas Gohr * 205*80852c15SAndreas Gohr * @param int $start 206*80852c15SAndreas Gohr * @param int $limit 207*80852c15SAndreas Gohr * @return array 208*80852c15SAndreas Gohr */ 209*80852c15SAndreas Gohr //public function retrieveGroups($start = 0, $limit = 0) { 210*80852c15SAndreas Gohr // FIXME implement 211*80852c15SAndreas Gohr // return array(); 212*80852c15SAndreas Gohr //} 213*80852c15SAndreas Gohr 214*80852c15SAndreas Gohr /** 215*80852c15SAndreas Gohr * Return case sensitivity of the backend 216*80852c15SAndreas Gohr * 217*80852c15SAndreas Gohr * When your backend is caseinsensitive (eg. you can login with USER and 218*80852c15SAndreas Gohr * user) then you need to overwrite this method and return false 219*80852c15SAndreas Gohr * 220*80852c15SAndreas Gohr * @return bool 221*80852c15SAndreas Gohr */ 222*80852c15SAndreas Gohr public function isCaseSensitive() { 223*80852c15SAndreas Gohr return true; 224*80852c15SAndreas Gohr } 225*80852c15SAndreas Gohr 226*80852c15SAndreas Gohr /** 227*80852c15SAndreas Gohr * Sanitize a given username 228*80852c15SAndreas Gohr * 229*80852c15SAndreas Gohr * This function is applied to any user name that is given to 230*80852c15SAndreas Gohr * the backend and should also be applied to any user name within 231*80852c15SAndreas Gohr * the backend before returning it somewhere. 232*80852c15SAndreas Gohr * 233*80852c15SAndreas Gohr * This should be used to enforce username restrictions. 234*80852c15SAndreas Gohr * 235*80852c15SAndreas Gohr * @param string $user username 236*80852c15SAndreas Gohr * @return string the cleaned username 237*80852c15SAndreas Gohr */ 238*80852c15SAndreas Gohr public function cleanUser($user) { 239*80852c15SAndreas Gohr return $user; 240*80852c15SAndreas Gohr } 241*80852c15SAndreas Gohr 242*80852c15SAndreas Gohr /** 243*80852c15SAndreas Gohr * Sanitize a given groupname 244*80852c15SAndreas Gohr * 245*80852c15SAndreas Gohr * This function is applied to any groupname that is given to 246*80852c15SAndreas Gohr * the backend and should also be applied to any groupname within 247*80852c15SAndreas Gohr * the backend before returning it somewhere. 248*80852c15SAndreas Gohr * 249*80852c15SAndreas Gohr * This should be used to enforce groupname restrictions. 250*80852c15SAndreas Gohr * 251*80852c15SAndreas Gohr * Groupnames are to be passed without a leading '@' here. 252*80852c15SAndreas Gohr * 253*80852c15SAndreas Gohr * @param string $group groupname 254*80852c15SAndreas Gohr * @return string the cleaned groupname 255*80852c15SAndreas Gohr */ 256*80852c15SAndreas Gohr public function cleanGroup($group) { 257*80852c15SAndreas Gohr return $group; 258*80852c15SAndreas Gohr } 259*80852c15SAndreas Gohr 260*80852c15SAndreas Gohr /** 261*80852c15SAndreas Gohr * Check Session Cache validity [implement only where required/possible] 262*80852c15SAndreas Gohr * 263*80852c15SAndreas Gohr * DokuWiki caches user info in the user's session for the timespan defined 264*80852c15SAndreas Gohr * in $conf['auth_security_timeout']. 265*80852c15SAndreas Gohr * 266*80852c15SAndreas Gohr * This makes sure slow authentication backends do not slow down DokuWiki. 267*80852c15SAndreas Gohr * This also means that changes to the user database will not be reflected 268*80852c15SAndreas Gohr * on currently logged in users. 269*80852c15SAndreas Gohr * 270*80852c15SAndreas Gohr * To accommodate for this, the user manager plugin will touch a reference 271*80852c15SAndreas Gohr * file whenever a change is submitted. This function compares the filetime 272*80852c15SAndreas Gohr * of this reference file with the time stored in the session. 273*80852c15SAndreas Gohr * 274*80852c15SAndreas Gohr * This reference file mechanism does not reflect changes done directly in 275*80852c15SAndreas Gohr * the backend's database through other means than the user manager plugin. 276*80852c15SAndreas Gohr * 277*80852c15SAndreas Gohr * Fast backends might want to return always false, to force rechecks on 278*80852c15SAndreas Gohr * each page load. Others might want to use their own checking here. If 279*80852c15SAndreas Gohr * unsure, do not override. 280*80852c15SAndreas Gohr * 281*80852c15SAndreas Gohr * @param string $user - The username 282*80852c15SAndreas Gohr * @return bool 283*80852c15SAndreas Gohr */ 284*80852c15SAndreas Gohr //public function useSessionCache($user) { 285*80852c15SAndreas Gohr // FIXME implement 286*80852c15SAndreas Gohr //} 287*80852c15SAndreas Gohr} 288*80852c15SAndreas Gohr 289*80852c15SAndreas Gohr// vim:ts=4:sw=4:et: