Passed
Push — master ( da209f...9657eb )
by Benjamin
05:40 queued 03:05
created

Google::getManagerUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @link      https://dukt.net/social/
4
 * @copyright Copyright (c) 2019, Dukt
5
 * @license   https://github.com/dukt/social/blob/v2/LICENSE.md
6
 */
7
8
namespace dukt\social\loginproviders;
9
10
use dukt\social\base\LoginProvider;
11
use dukt\social\models\Token;
12
13
/**
14
 * Google represents the Google login provider.
15
 *
16
 * @author  Dukt <[email protected]>
17
 * @since   1.0
18
 */
19
class Google extends LoginProvider
20
{
21
    // Public Methods
22
    // =========================================================================
23
24
    /**
25
     * @inheritdoc
26
     */
27
    public function getName(): string
28
    {
29
        return 'Google';
30
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35
    public function getDefaultOauthScope(): array
36
    {
37
        return [
38
            'https://www.googleapis.com/auth/userinfo.profile',
39
            'https://www.googleapis.com/auth/userinfo.email'
40
        ];
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46
    public function getManagerUrl()
47
    {
48
        return 'https://code.google.com/apis/console/';
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54
    public function getScopeDocsUrl()
55
    {
56
        return 'https://developers.google.com/identity/protocols/googlescopes';
57
    }
58
59
    /**
60
     * @inheritdoc
61
     */
62
    public function getDefaultUserFieldMapping(): array
63
    {
64
        return [
65
            'id' => '{{ profile.getId() }}',
66
            'email' => '{{ profile.getEmail() }}',
67
            'username' => '{{ profile.getEmail() }}',
68
            'photo' => '{{ profile.getAvatar() }}',
69
        ];
70
    }
71
72
    /**
73
     * @inheritdoc
74
     */
75
    public function getOauthProviderConfig(): array
76
    {
77
        $config = parent::getOauthProviderConfig();
78
79
        if (empty($config['options']['useOidcMode'])) {
80
            $config['options']['useOidcMode'] = true;
81
        }
82
83
        return $config;
84
    }
85
86
    /**
87
     * Returns the login provider’s OAuth provider.
88
     *
89
     * @return \League\OAuth2\Client\Provider\Google
90
     * @throws \yii\base\InvalidConfigException
91
     */
92
    public function getOauthProvider(): \League\OAuth2\Client\Provider\Google
93
    {
94
        $config = $this->getOauthProviderConfig();
95
96
        return new \League\OAuth2\Client\Provider\Google($config['options']);
97
    }
98
}
99