Google::initUserAttributes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\AuthClient\Client;
6
7
use Yiisoft\Yii\AuthClient\OAuth2;
8
9
/**
10
 * Google allows authentication via Google OAuth.
11
 *
12
 * In order to use Google OAuth you must create a project at <https://console.developers.google.com/project>
13
 * and setup its credentials at <https://console.developers.google.com/project/[yourProjectId]/apiui/credential>.
14
 * In order to enable using scopes for retrieving user attributes, you should also enable Google+ API at
15
 * <https://console.developers.google.com/project/[yourProjectId]/apiui/api/plus>
16
 *
17
 * @link https://console.developers.google.com/project
18
 */
19
class Google extends OAuth2
20
{
21
    protected string $authUrl = 'https://accounts.google.com/o/oauth2/auth';
22
    protected string $tokenUrl = 'https://accounts.google.com/o/oauth2/token';
23
    protected string $endpoint = 'https://www.googleapis.com/plus/v1';
24
25
    /**
26
     * @return string service name.
27
     */
28
    public function getName(): string
29
    {
30
        return 'google';
31
    }
32
33
    /**
34
     * @return string service title.
35
     */
36
    public function getTitle(): string
37
    {
38
        return 'Google';
39
    }
40
41
    protected function getDefaultScope(): string
42
    {
43
        return 'profile email';
44
    }
45
46
    protected function initUserAttributes(): array
47
    {
48
        return $this->api('people/me', 'GET');
49
    }
50
}
51