Skip to content

Commit 290e9b1

Browse files
committed
automatic style fixes and new workflows
1 parent db85e03 commit 290e9b1

File tree

16 files changed

+123
-146
lines changed

16 files changed

+123
-146
lines changed

.github/workflows/dokuwiki.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: DokuWiki Default Tasks
2+
on:
3+
push:
4+
pull_request:
5+
schedule:
6+
- cron: '14 0 5 * *'
7+
8+
9+
jobs:
10+
all:
11+
uses: dokuwiki/github-action/.github/workflows/all.yml@main

.github/workflows/phpTestLinux.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.

Adapter.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace dokuwiki\plugin\oauth;
44

5+
use dokuwiki\Extension\EventHandler;
6+
use dokuwiki\Extension\Event;
57
use dokuwiki\Extension\ActionPlugin;
68
use OAuth\Common\Consumer\Credentials;
79
use OAuth\Common\Http\Exception\TokenResponseException;
@@ -32,15 +34,15 @@ abstract class Adapter extends ActionPlugin
3234
*
3335
* @inheritDoc
3436
*/
35-
public function register(\Doku_Event_Handler $controller)
37+
public function register(EventHandler $controller)
3638
{
3739
$controller->register_hook('PLUGIN_OAUTH_BACKEND_REGISTER', 'AFTER', $this, 'handleRegister');
3840
}
3941

4042
/**
4143
* Auto register this plugin with the oAuth authentication plugin
4244
*/
43-
public function handleRegister(\Doku_Event $event, $param)
45+
public function handleRegister(Event $event, $param)
4446
{
4547
$event->data[$this->getServiceID()] = $this;
4648
}
@@ -64,6 +66,7 @@ public function initOAuthService($storageId = '')
6466

6567
$serviceFactory = new ServiceFactory();
6668
$serviceFactory->setHttpClient(new HTTPClient());
69+
6770
$servicename = $this->getServiceID();
6871
$serviceclass = $this->registerServiceClass();
6972
if ($serviceclass) {
@@ -143,8 +146,10 @@ public function refreshOutdatedToken()
143146
}
144147

145148
$token = $oauth->getStorage()->retrieveAccessToken($oauth->service());
146-
if ($token->getEndOfLife() < 0 ||
147-
$token->getEndOfLife() - time() > 3600) {
149+
if (
150+
$token->getEndOfLife() < 0 ||
151+
$token->getEndOfLife() - time() > 3600
152+
) {
148153
// token is still good
149154
return;
150155
}
@@ -168,7 +173,7 @@ public function refreshOutdatedToken()
168173
* but might need to be overwritten for specific services
169174
*
170175
* @throws TokenResponseException
171-
* @throws Exception
176+
* @throws \Exception
172177
*/
173178
public function login()
174179
{
@@ -182,7 +187,7 @@ public function login()
182187
$parameters['state'] = urlencode(base64_encode(json_encode(
183188
[
184189
'animal' => $animal,
185-
'state' => md5(rand()),
190+
'state' => md5(random_int(0, mt_getrandmax())),
186191
]
187192
)));
188193
$oauth->getStorage()->storeAuthorizationState($oauth->service(), $parameters['state']);
@@ -221,12 +226,10 @@ public function checkToken()
221226
$oauth = $this->getOAuthService();
222227

223228
if (is_a($oauth, Abstract2Service::class)) {
224-
/** @var Abstract2Service $oauth */
225229
if (!$INPUT->get->has('code')) return false;
226230
$state = $INPUT->get->str('state', null);
227231
$accessToken = $oauth->requestAccessToken($INPUT->get->str('code'), $state);
228232
} else {
229-
/** @var Abstract1Service $oauth */
230233
if (!$INPUT->get->has('oauth_token')) return false;
231234
/** @var TokenInterface $token */
232235
$token = $oauth->getStorage()->retrieveAccessToken($this->getServiceID());
@@ -239,7 +242,8 @@ public function checkToken()
239242

240243
if (
241244
$accessToken->getEndOfLife() !== $accessToken::EOL_NEVER_EXPIRES &&
242-
!$accessToken->getRefreshToken()) {
245+
!$accessToken->getRefreshToken()
246+
) {
243247
msg('Service did not provide a Refresh Token. You will be logged out when the session expires.');
244248
}
245249

@@ -256,7 +260,7 @@ public function loginButton()
256260
global $ID;
257261

258262
$attr = buildAttributes([
259-
'href' => wl($ID, array('oauthlogin' => $this->getServiceID()), false, '&'),
263+
'href' => wl($ID, ['oauthlogin' => $this->getServiceID()], false, '&'),
260264
'class' => 'plugin_oauth_' . $this->getServiceID(),
261265
'style' => 'background-color: ' . $this->getColor(),
262266
]);

Exception.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,4 @@ public function setContext(array $context)
4343
{
4444
$this->context = $context;
4545
}
46-
4746
}

HTTPClient.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
*/
1313
class HTTPClient implements ClientInterface
1414
{
15-
1615
/** @inheritDoc */
1716
public function retrieveResponse(
1817
UriInterface $endpoint,
1918
$requestBody,
20-
array $extraHeaders = array(),
19+
array $extraHeaders = [],
2120
$method = 'POST'
2221
) {
23-
$http = new DokuHTTPClient;
22+
$http = new DokuHTTPClient();
2423
$http->keep_alive = false;
2524
$http->headers = array_merge($http->headers, $extraHeaders);
2625

OAuthManager.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function startFlow($servicename)
2222

2323
$session = Session::getInstance();
2424
$session->setLoginData($servicename, $ID);
25+
2526
$service = $this->loadService($servicename);
2627
$service->initOAuthService();
2728
$service->login(); // redirects
@@ -36,9 +37,7 @@ public function startFlow($servicename)
3637
*/
3738
public function continueFlow()
3839
{
39-
return $this->loginByService() or
40-
$this->loginBySession() or
41-
$this->loginByCookie();
40+
return $this->loginByService() || $this->loginBySession() || $this->loginByCookie();
4241
}
4342

4443
/**
@@ -62,6 +61,7 @@ protected function loginByService()
6261
if (!$logindata) return false;
6362
$service = $this->loadService($logindata['servicename']);
6463
$service->initOAuthService();
64+
6565
$session->clearLoginData();
6666

6767
// oAuth login
@@ -196,14 +196,14 @@ protected function validateUserData($userdata, $servicename)
196196
$hlp = plugin_load('helper', 'oauth');
197197

198198
if (!$hlp->checkMail($userdata['mail'])) {
199-
throw new Exception('rejectedEMail', [join(', ', $hlp->getValidDomains())]);
199+
throw new Exception('rejectedEMail', [implode(', ', $hlp->getValidDomains())]);
200200
}
201201

202202
// make username from mail if empty
203203
if (!isset($userdata['user'])) $userdata['user'] = '';
204204
$userdata['user'] = $auth->cleanUser((string)$userdata['user']);
205205
if ($userdata['user'] === '') {
206-
list($userdata['user']) = explode('@', $userdata['mail']);
206+
[$userdata['user']] = explode('@', $userdata['mail']);
207207
}
208208

209209
// make full name from username if empty
@@ -238,7 +238,7 @@ protected function processUserData($userdata, $servicename)
238238
if ($localUser) {
239239
$localUserInfo = $auth->getUserData($localUser);
240240
$localUserInfo['user'] = $localUser;
241-
if(isset($localUserInfo['pass'])) unset($localUserInfo['pass']);
241+
if (isset($localUserInfo['pass'])) unset($localUserInfo['pass']);
242242

243243
// check if the user allowed access via this service
244244
if (!in_array($auth->cleanGroup($servicename), $localUserInfo['grps'])) {
@@ -312,5 +312,4 @@ protected function loadService($servicename)
312312
if ($srv === null) throw new Exception("No such service $servicename");
313313
return $srv;
314314
}
315-
316315
}

RedirectSetting.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
/**
88
* Custom Setting to display the default redirect URL
99
*/
10-
class RedirectSetting extends Setting {
11-
10+
class RedirectSetting extends Setting
11+
{
1212
/** @inheritdoc */
13-
function update($input) {
13+
public function update($input)
14+
{
1415
return true;
1516
}
1617

@@ -22,11 +23,10 @@ public function html(\admin_plugin_config $plugin, $echo = false)
2223
$hlp = plugin_load('helper', 'oauth');
2324

2425
$key = htmlspecialchars($this->key);
25-
$value = '<code>'.$hlp->redirectURI().'</code>';
26+
$value = '<code>' . $hlp->redirectURI() . '</code>';
2627

27-
$label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>';
28-
$input = '<div>'.$value.'</div>';
29-
return array($label, $input);
28+
$label = '<label for="config___' . $key . '">' . $this->prompt($plugin) . '</label>';
29+
$input = '<div>' . $value . '</div>';
30+
return [$label, $input];
3031
}
31-
3232
}

Service/AbstractOAuth2Base.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*/
1313
abstract class AbstractOAuth2Base extends AbstractService
1414
{
15-
1615
/** @inheritdoc */
1716
protected function parseAccessTokenResponse($responseBody)
1817
{
@@ -55,5 +54,4 @@ public function isValidScope($scope)
5554
{
5655
return true;
5756
}
58-
5957
}

Session.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class Session
99
{
1010
/** @var Session */
11-
protected static $instance = null;
11+
protected static $instance;
1212

1313
/**
1414
* hidden constructor
@@ -52,10 +52,7 @@ public function setLoginData($servicename, $id)
5252
*/
5353
public function getLoginData()
5454
{
55-
if (isset($_SESSION[DOKU_COOKIE]['auth']['oauth'])) {
56-
return $_SESSION[DOKU_COOKIE]['auth']['oauth'];
57-
}
58-
return false;
55+
return $_SESSION[DOKU_COOKIE]['auth']['oauth'] ?? false;
5956
}
6057

6158
/**
@@ -83,10 +80,10 @@ public function setUser($userdata, $resettime = true)
8380
global $USERINFO;
8481

8582
if (
86-
!isset($userdata['user']) or
87-
!isset($userdata['name']) or
88-
!isset($userdata['mail']) or
89-
!isset($userdata['grps']) or
83+
!isset($userdata['user']) ||
84+
!isset($userdata['name']) ||
85+
!isset($userdata['mail']) ||
86+
!isset($userdata['grps']) ||
9087
!is_array($userdata['grps'])
9188
) {
9289
throw new Exception('Missing user data, cannot save to session');
@@ -111,10 +108,7 @@ public function setUser($userdata, $resettime = true)
111108
*/
112109
public function getUser()
113110
{
114-
if (isset($_SESSION[DOKU_COOKIE]['auth']['info'])) {
115-
return $_SESSION[DOKU_COOKIE]['auth']['info'];
116-
}
117-
return false;
111+
return $_SESSION[DOKU_COOKIE]['auth']['info'] ?? false;
118112
}
119113

120114
/**
@@ -133,7 +127,17 @@ public function setCookie($servicename, $storageId)
133127
$cookie = "$servicename|oauth|$storageId";
134128
$cookieDir = empty($conf['cookiedir']) ? DOKU_REL : $conf['cookiedir'];
135129
$time = time() + $validityPeriodInSeconds;
136-
setcookie(DOKU_COOKIE, $cookie, $time, $cookieDir, '', ($conf['securecookie'] && is_ssl()), true);
130+
setcookie(
131+
DOKU_COOKIE,
132+
$cookie,
133+
[
134+
'expires' => $time,
135+
'path' => $cookieDir,
136+
'domain' => '',
137+
'secure' => $conf['securecookie'] && is_ssl(),
138+
'httponly' => true
139+
]
140+
);
137141
}
138142

139143
/**
@@ -144,7 +148,7 @@ public function setCookie($servicename, $storageId)
144148
public function getCookie()
145149
{
146150
if (!isset($_COOKIE[DOKU_COOKIE])) return false;
147-
list($servicename, $oauth, $storageId) = explode('|', $_COOKIE[DOKU_COOKIE]);
151+
[$servicename, $oauth, $storageId] = explode('|', $_COOKIE[DOKU_COOKIE]);
148152
if ($oauth !== 'oauth') return false;
149153
return ['servicename' => $servicename, 'storageId' => $storageId];
150154
}
@@ -173,6 +177,5 @@ public function clear()
173177
{
174178
//FIXME clear cookie?
175179
$this->clearLoginData();
176-
177180
}
178181
}

Storage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function loadServiceFile($service)
4545
if (file_exists($file)) {
4646
return unserialize(io_readFile($file, false));
4747
} else {
48-
return array();
48+
return [];
4949
}
5050
}
5151

0 commit comments

Comments
 (0)