1<?php
2
3use dokuwiki\plugin\oauthgoogle\Google;
4
5/**
6 * Service Implementation for oAuth Google authentication
7 */
8class action_plugin_oauthgoogle extends \dokuwiki\plugin\oauth\Adapter
9{
10    /**
11     * We use our own, modified version of the Google service
12     * @inheritdoc
13     */
14    public function registerServiceClass()
15    {
16        return Google::class;
17    }
18
19    /** * @inheritDoc */
20    public function getUser()
21    {
22        $oauth = $this->getOAuthService();
23        $data = array();
24
25        $result = json_decode($oauth->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
26
27        $data['user'] = $result['name'];
28        $data['name'] = $result['name'];
29        $data['mail'] = $result['email'];
30
31        return $data;
32    }
33
34    /** @inheritDoc */
35    public function getScopes()
36    {
37        return [Google::SCOPE_USERINFO_EMAIL, Google::SCOPE_USERINFO_PROFILE];
38    }
39
40    /** @inheritDoc */
41    public function getLabel()
42    {
43        return 'Google';
44    }
45
46    /** @inheritDoc */
47    public function getColor()
48    {
49        return '#4285F4';
50    }
51
52}
53