-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathaction.php
72 lines (61 loc) · 1.67 KB
/
action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
use dokuwiki\plugin\oauth\Adapter;
use dokuwiki\plugin\oauthkeycloak\Keycloak;
/**
* Service Implementation for Keycloak authentication
*/
class action_plugin_oauthkeycloak extends Adapter
{
/** @inheritdoc */
public function registerServiceClass()
{
return Keycloak::class;
}
/**
* @inheritdoc
* @throws \OAuth\Common\Exception\Exception
*/
public function logout()
{
/** @var Keycloak */
$oauth = $this->getOAuthService();
$oauth->logout();
}
/** * @inheritDoc */
public function getUser()
{
/** @var Keycloak */
$oauth = $this->getOAuthService();
$data = array();
$url = $oauth->getEndpoint(Keycloak::ENDPOINT_USERINFO);
$raw = $oauth->request($url);
if (!$raw) throw new OAuthException('Failed to fetch data from userinfo endpoint');
$result = json_decode($raw, true);
if (!$result) throw new OAuthException('Failed to parse data from userinfo endpoint');
$data = array();
$data['user'] = $result['preferred_username'];
$data['name'] = $result['name'];
$data['mail'] = $result['email'];
if (array_key_exists('groups', $result)) {
$data['grps'] = $result['groups'];
} else {
$data['grps'] = [];
}
return $data;
}
/** @inheritdoc */
public function getScopes()
{
return array(Keycloak::SCOPE_OPENID);
}
/** @inheritDoc */
public function getLabel()
{
return $this->getConf('label');
}
/** @inheritDoc */
public function getColor()
{
return $this->getConf('color');
}
}