Passed
Push — master ( 9511a8...de0418 )
by Benjamin
07:41 queued 03:07
created

Google::getDefaultScope()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @link      https://dukt.net/social/
4
 * @copyright Copyright (c) 2018, 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
     * Returns the login provider’s OAuth provider.
74
     *
75
     * @return \Dukt\OAuth2\Client\Provider\Google
76
     * @throws \yii\base\InvalidConfigException
77
     */
78
    public function getOauthProvider(): \Dukt\OAuth2\Client\Provider\Google
79
    {
80
        $config = $this->getOauthProviderConfig();
81
82
        return new \Dukt\OAuth2\Client\Provider\Google($config['options']);
83
    }
84
}
85