1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* SocialConnect project |
4
|
|
|
* @author: Patsura Dmitry https://github.com/ovr <[email protected]> |
5
|
|
|
* @author Alexander Fedyashov <[email protected]> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SocialConnect\OpenIDConnect\Provider; |
9
|
|
|
|
10
|
|
|
use SocialConnect\Provider\AccessTokenInterface; |
11
|
|
|
use SocialConnect\Provider\Exception\InvalidResponse; |
12
|
|
|
use SocialConnect\OpenIDConnect\AbstractProvider; |
13
|
|
|
use SocialConnect\Common\Entity\User; |
14
|
|
|
use SocialConnect\Common\Hydrator\ObjectMap; |
15
|
|
|
use SocialConnect\OpenIDConnect\Exception\InvalidJWT; |
16
|
|
|
use SocialConnect\Common\Http\Client\Client; |
17
|
|
|
use Exception; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class Provider |
21
|
|
|
* @package SocialConnect\Google |
22
|
|
|
*/ |
23
|
|
|
class PixelPin extends AbstractProvider |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
public function getOpenIdUrl() |
29
|
|
|
{ |
30
|
|
|
return 'https://login.pixelpin.io/.well-known/openid-configuration'; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
public function getBaseUri() |
37
|
|
|
{ |
38
|
|
|
return 'https://login.pixelpin.io/'; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function getAuthorizeUri() |
45
|
|
|
{ |
46
|
|
|
return 'https://login.pixelpin.io/connect/authorize'; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
public function getRequestTokenUri() |
53
|
|
|
{ |
54
|
|
|
return 'https://login.pixelpin.io/connect/token'; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
|
|
public function getName() |
61
|
|
|
{ |
62
|
|
|
return 'pixelpin'; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
|
|
public function getIdentity(AccessTokenInterface $accessToken) |
69
|
|
|
{ |
70
|
|
|
$response = $this->httpClient->request( |
71
|
|
|
$this->getBaseUri() . 'connect/userinfo', |
72
|
|
|
[ |
73
|
|
|
'access_token' => $accessToken->getToken() |
74
|
|
|
], |
75
|
|
|
Client::GET, |
76
|
|
|
[ |
77
|
|
|
'Authorization' => 'Bearer ' . $accessToken->getToken() |
78
|
|
|
] |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
if (!$response->isSuccess()) { |
82
|
|
|
throw new InvalidResponse( |
83
|
|
|
'API response with error code', |
84
|
|
|
$response |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$result = $response->json(); |
89
|
|
|
if (!$result) { |
90
|
|
|
throw new InvalidResponse( |
91
|
|
|
'API response is not a valid JSON object', |
92
|
|
|
$response->getBody() |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$hydrator = new ObjectMap( |
97
|
|
|
[ |
98
|
|
|
'sub' => 'id', |
99
|
|
|
'given_name' => 'firstname', |
100
|
|
|
'family_name' => 'lastname', |
101
|
|
|
'email' => 'email', |
102
|
|
|
'display_name' => 'fullname', |
103
|
|
|
'gender' => 'gender', |
104
|
|
|
'phone_number' => 'phone', |
105
|
|
|
'birthdate' => 'birthdate', |
106
|
|
|
'street_address' => 'address', |
107
|
|
|
'town_city' => 'townCity', |
108
|
|
|
'region' => 'region', |
109
|
|
|
'postal_code' => 'postalCode', |
110
|
|
|
'country' => 'country' |
111
|
|
|
] |
112
|
|
|
); |
113
|
|
|
|
114
|
|
|
return $hydrator->hydrate(new User(), $result); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|