180852c15SAndreas Gohr<?php 280852c15SAndreas Gohr/** 380852c15SAndreas Gohr * DokuWiki Plugin oauth (Auth Component) 480852c15SAndreas Gohr * 580852c15SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 680852c15SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 780852c15SAndreas Gohr */ 880852c15SAndreas Gohr 980852c15SAndreas Gohr// must be run within Dokuwiki 1080852c15SAndreas Gohrif(!defined('DOKU_INC')) die(); 1180852c15SAndreas Gohr 12*f10e09e2SAndreas Gohrclass auth_plugin_oauth extends auth_plugin_authplain { 1380852c15SAndreas Gohr 1480852c15SAndreas Gohr public function __construct() { 15*f10e09e2SAndreas Gohr parent::__construct(); 1680852c15SAndreas Gohr 1780852c15SAndreas Gohr 18*f10e09e2SAndreas Gohr $this->cando['external'] = true; 1980852c15SAndreas Gohr } 2080852c15SAndreas Gohr 2180852c15SAndreas Gohr 22*f10e09e2SAndreas Gohr function trustExternal($user, $pass, $sticky = false) { 23*f10e09e2SAndreas Gohr global $USERINFO, $ID, $INPUT; 2480852c15SAndreas Gohr 25*f10e09e2SAndreas Gohr // get form login info 26*f10e09e2SAndreas Gohr if(!empty($user)){ 27*f10e09e2SAndreas Gohr return auth_login($user, $pass, $sticky); 28*f10e09e2SAndreas Gohr } 2980852c15SAndreas Gohr 30*f10e09e2SAndreas Gohr if($INPUT->has('oa')) { 31*f10e09e2SAndreas Gohr /** @var helper_plugin_oauth $hlp */ 32*f10e09e2SAndreas Gohr $hlp = plugin_load('helper', 'oauth'); 33*f10e09e2SAndreas Gohr $service = $hlp->loadService($INPUT->str('oa')); 34*f10e09e2SAndreas Gohr if(is_null($service)) return false; 3580852c15SAndreas Gohr 3680852c15SAndreas Gohr 37*f10e09e2SAndreas Gohr 38*f10e09e2SAndreas Gohr if($service->checkToken()) { 39*f10e09e2SAndreas Gohr $uinfo = $service->getUser(); 40*f10e09e2SAndreas Gohr $this->setUserSession($uinfo); 4180852c15SAndreas Gohr return true; 42*f10e09e2SAndreas Gohr } 4380852c15SAndreas Gohr } 4480852c15SAndreas Gohr 4580852c15SAndreas Gohr return false; 4680852c15SAndreas Gohr } 4780852c15SAndreas Gohr 4880852c15SAndreas Gohr 49*f10e09e2SAndreas Gohr protected function setUserSession($data) { 50*f10e09e2SAndreas Gohr global $USERINFO; 5180852c15SAndreas Gohr 52*f10e09e2SAndreas Gohr // reopen session 53*f10e09e2SAndreas Gohr session_start(); 5480852c15SAndreas Gohr 55*f10e09e2SAndreas Gohr $USERINFO = $data; 56*f10e09e2SAndreas Gohr $_SERVER['REMOTE_USER'] = $data['user']; 57*f10e09e2SAndreas Gohr $_SESSION[DOKU_COOKIE]['auth']['user'] = $data['user']; 58*f10e09e2SAndreas Gohr $_SESSION[DOKU_COOKIE]['auth']['pass'] = $data['pass']; 59*f10e09e2SAndreas Gohr $_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO; 6080852c15SAndreas Gohr 61*f10e09e2SAndreas Gohr // close session again 62*f10e09e2SAndreas Gohr session_write_close(); 6380852c15SAndreas Gohr } 6480852c15SAndreas Gohr 6580852c15SAndreas Gohr} 6680852c15SAndreas Gohr 6780852c15SAndreas Gohr// vim:ts=4:sw=4:et: