1<?php 2 3namespace dokuwiki\plugin\oauthdrkserver; 4 5use dokuwiki\plugin\oauth\Service\AbstractOAuth2Base; 6use OAuth\Common\Http\Uri\Uri; 7 8/** 9 * Custom Service for drkserver oAuth 10 * 11 * @author Daniel Weisshaar <daniwei-dev@gmx.de> 12 */ 13class DRKServer extends AbstractOAuth2Base 14{ 15 /** 16 * Defined scopes 17 */ 18 19 const USERINFO_JSON_USER = 'name'; 20 const USERINFO_JSON_NAME = 'given_name'; 21 const USERINFO_JSON_MAIL = 'email'; 22 const USERINFO_JSON_GRPS = 'profile'; 23 24 const SCOPE_OPENID = 'openid'; 25 const SCOPE_EMAIL = 'email'; 26 const SCOPE_PROFILE = 'profile'; 27 28 const BUTTON_LABEL = 'drkserver'; 29 const BUTTON_BACKGROUND_COLOR = '#FFFFFF; color: #000000'; // injecting the font color for the button text here prevents changing the oauth plugin 30 31 const ENVIRONMENT_PATH = array('drkserver', 'drkdemo'); // possible environment paths, [0]=>'drkserver', [1]=>'drkdemo' 32 33 private static $useDemoEnv = false; 34 35 /** @inheritdoc */ 36 public function getAuthorizationEndpoint() 37 { 38 $authUrl = self::getDrkServerOpenidPath() . 'auth'; 39 return new Uri($authUrl); 40 41 } 42 43 /** @inheritdoc */ 44 public function getAccessTokenEndpoint() 45 { 46 $tokenUrl = self::getDrkServerOpenidPath() . 'token'; 47 return new Uri($tokenUrl); 48 } 49 50 /** @inheritdoc */ 51 public function getUserInfoEndpoint() 52 { 53 $userUrl = self::getDrkServerOpenidPath() . 'userinfo'; 54 return new Uri($userUrl); 55 } 56 57 /** 58 * @inheritdoc 59 */ 60 protected function getAuthorizationMethod() 61 { 62 return static::AUTHORIZATION_METHOD_HEADER_BEARER; 63 } 64 65 /** 66 * @inheritdoc 67 */ 68 private function getDrkServerOpenidPath() 69 { 70 // insert the choosen environment into the openid path 71 $path = 'https://login.drkserver.org/auth/realms/' . self::ENVIRONMENT_PATH[self::$useDemoEnv] . '/protocol/openid-connect/'; 72 73 return $path; 74 } 75 76 /** 77 * Decide between the production environment and the demo environment 78 * 79 * @param $pUseDemoMode boolean true for using demo environment, otherwise use production environment 80 */ 81 public static function setUseDemoEnvironment($pUseDemoEnv=false) 82 { 83 self::$useDemoEnv = $pUseDemoEnv; 84 } 85} 86