1<?php
2
3use dokuwiki\plugin\oauthwechange\Wechange;
4
5/**
6 * Service Implementation for oAuth WECHANGE authentication
7 */
8class action_plugin_oauthwechange extends \dokuwiki\plugin\oauth\Adapter
9{
10
11    /** @inheritdoc */
12    public function registerServiceClass()
13    {
14        return Wechange::class;
15    }
16
17    /** * @inheritDoc */
18    public function getUser()
19    {
20        $oauth = $this->getOAuthService();
21        $data = [];
22
23        // basic user data
24        $json = $oauth->request($this->getConf('baseurl') . '/o/me?format=json');
25        $result = json_decode($json, true);
26        $data['user'] = $result['id'];
27        $data['name'] = $result['name'];
28        $data['mail'] = $result['email'];
29
30        if (isset($result['group']) && is_array($result['group'])) {
31            foreach ($result['group'] as $id => $slug) {
32                $data['grps'][] = $id;
33            }
34        }
35
36        return $data;
37    }
38
39    /** @inheritDoc */
40    public function getScopes()
41    {
42        return ['read'];
43    }
44
45    /** @inheritDoc */
46    public function getLabel()
47    {
48        return $this->getConf('label', 'WECHANGE');
49    }
50
51    /** @inheritDoc */
52    public function getColor()
53    {
54        return '#34b4b5';
55    }
56
57}
58