1<?php 2 3use dokuwiki\plugin\oauth\Adapter; 4use dokuwiki\plugin\oauthdrkserver\DRKServer; 5 6// Check if the oauth plugin is installed 7if(!plugin_load('helper', 'oauth')){ 8 msg('The plugin oauthdrkserver requires the oauth plugin. Please install it.', -1); 9 return; 10} 11 12/** 13 * Service Implementation for oAuth drkserver authentication 14 * 15 * @author Daniel Weisshaar <daniwei-dev@gmx.de> 16 */ 17class action_plugin_oauthdrkserver extends Adapter 18{ 19 /** @inheritdoc */ 20 public function registerServiceClass() 21 { 22 $useDemoEnv = $this->getConf('demoenv'); 23 DRKServer::setUseDemoEnvironment($useDemoEnv); 24 return DRKServer::class; 25 } 26 27 /** * @inheritDoc */ 28 public function getUser() 29 { 30 $oauth = $this->getOAuthService(); 31 $data = array(); 32 33 $result = json_decode($oauth->request(DRKServer::getUserInfoEndpoint()), true); 34 35 $data['user'] = $result[DRKServer::USERINFO_JSON_USER]; 36 $data['name'] = $result[DRKServer::USERINFO_JSON_NAME]; 37 $data['mail'] = $result[DRKServer::USERINFO_JSON_MAIL]; 38 $data['grps'] = $result[DRKServer::USERINFO_JSON_GRPS]; 39 40 return $data; 41 } 42 43 /** @inheritdoc */ 44 public function getScopes() 45 { 46 $scopes = [DRKServer::SCOPE_OPENID, DRKServer::SCOPE_EMAIL, DRKServer::SCOPE_PROFILE]; 47 return $scopes; 48 } 49 50 /** @inheritDoc */ 51 public function getLabel() 52 { 53 return DRKServer::BUTTON_LABEL; 54 } 55 56 /** @inheritDoc */ 57 public function getColor() 58 { 59 return DRKServer::BUTTON_BACKGROUND_COLOR; 60 } 61} 62