-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.php
53 lines (41 loc) · 1.22 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
<?php
use dokuwiki\plugin\oauth\Adapter;
use dokuwiki\plugin\oauthcognito\Cognito;
/**
* OAuth Cognito authentication
*/
class action_plugin_oauthcognito extends Adapter
{
/** @inheritdoc */
public function registerServiceClass()
{
return Cognito::class;
}
/** * @inheritDoc */
public function getUser()
{
$oauth = $this->getOAuthService();
$data = array();
$tokenExtras = $oauth->getStorage()->retrieveAccessToken($oauth->service())->getExtraParams();
$idToken = $tokenExtras['id_token'] ?? '';
$decodedObj = json_decode(base64_decode(str_replace('_', '/', str_replace('-','+',explode('.', $idToken)[1]))));
$result = (array)$decodedObj;
$data['user'] = $result['preferred_username'] ?? $result['cognito:username'];
$data['name'] = $result['name'] ?? $data['user'];
$data['mail'] = $result['email'];
if (isset($result['cognito:groups'])) {
$data['grps'] = $result['cognito:groups'];
}
return $data;
}
/** @inheritDoc */
public function getLabel()
{
return 'Cognito';
}
/** @inheritDoc */
public function getColor()
{
return '#404041';
}
}