1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* SocialConnect project |
4
|
|
|
* @author: Patsura Dmitry https://github.com/ovr <[email protected]> |
5
|
|
|
* @author Alexander Fedyashov <[email protected]> |
6
|
|
|
*/ |
7
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace SocialConnect\OpenIDConnect\Provider; |
10
|
|
|
|
11
|
|
|
use SocialConnect\Common\ArrayHydrator; |
12
|
|
|
use SocialConnect\Provider\AccessTokenInterface; |
13
|
|
|
use SocialConnect\OpenIDConnect\AbstractProvider; |
14
|
|
|
use SocialConnect\Common\Entity\User; |
15
|
|
|
|
16
|
|
|
class Google extends AbstractProvider |
17
|
|
|
{ |
18
|
|
|
const NAME = 'google'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* {@inheritdoc} |
22
|
|
|
*/ |
23
|
1 |
|
public function getOpenIdUrl() |
24
|
|
|
{ |
25
|
1 |
|
return 'https://accounts.google.com/.well-known/openid-configuration'; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
2 |
|
public function getBaseUri() |
32
|
|
|
{ |
33
|
2 |
|
return 'https://www.googleapis.com/'; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
1 |
|
public function getAuthorizeUri() |
40
|
|
|
{ |
41
|
1 |
|
return 'https://accounts.google.com/o/oauth2/auth'; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
1 |
|
public function getRequestTokenUri() |
48
|
|
|
{ |
49
|
1 |
|
return 'https://accounts.google.com/o/oauth2/token'; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
1 |
|
public function getName() |
56
|
|
|
{ |
57
|
1 |
|
return self::NAME; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
1 |
|
public function getIdentity(AccessTokenInterface $accessToken) |
64
|
|
|
{ |
65
|
1 |
|
$response = $this->request('GET', 'oauth2/v1/userinfo', [], $accessToken); |
66
|
|
|
|
67
|
1 |
|
$hydrator = new ArrayHydrator([ |
68
|
1 |
|
'id' => 'id', |
69
|
1 |
|
'given_name' => 'firstname', |
70
|
1 |
|
'family_name' => 'lastname', |
71
|
1 |
|
'email' => 'email', |
72
|
1 |
|
'verified_email' => 'emailVerified', |
73
|
1 |
|
'name' => 'fullname', |
74
|
|
|
'gender' => static function ($value, User $user) { |
75
|
|
|
$user->setSex($value); |
|
|
|
|
76
|
1 |
|
}, |
77
|
|
|
]); |
78
|
|
|
|
79
|
1 |
|
return $hydrator->hydrate(new User(), $response); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritdoc} |
84
|
|
|
*/ |
85
|
|
|
public function getScopeInline() |
86
|
|
|
{ |
87
|
|
|
return implode(' ', $this->scope); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.