1<?php
2
3use OAuth\OAuth2\Service\Facebook;
4
5/**
6 * Service Implementation for oAuth Facebook authentication
7 */
8class action_plugin_oauthfacebook extends \dokuwiki\plugin\oauth\Adapter
9{
10
11    /** * @inheritDoc */
12    public function getUser()
13    {
14        $oauth = $this->getOAuthService();
15        $data = array();
16
17        $result = json_decode($oauth->request('/me?fields=name,email'), true);
18
19        if (!empty($result['username'])) {
20            $data['user'] = $result['username'];
21        } else {
22            $data['user'] = $result['name'];
23        }
24        $data['name'] = $result['name'];
25        $data['mail'] = $result['email'];
26
27        return $data;
28    }
29
30    /** @inheritDoc */
31    public function getScopes()
32    {
33        return [Facebook::SCOPE_EMAIL];
34    }
35
36    /** @inheritDoc */
37    public function getLabel()
38    {
39        return 'Facebook';
40    }
41
42    /** @inheritDoc */
43    public function getColor()
44    {
45        return '#3b5998';
46    }
47
48}
49