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
|
|
|
$body = $response->getBody(); |
89
|
|
|
|
90
|
|
|
//throw new InvalidJWT($body); |
91
|
|
|
|
92
|
|
|
$result = json_decode($body); |
93
|
|
|
|
94
|
|
|
$sub2 = $result->sub; |
95
|
|
|
|
96
|
|
|
$firstName = (isset($result->given_name) ? $result->given_name : false); |
97
|
|
|
if ($firstName === false) { |
98
|
|
|
$given_name2 = 'Not Set'; |
99
|
|
|
} else { |
100
|
|
|
$given_name2 = $result->given_name; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$familyName = (isset($result->family_name) ? $result->family_name : false); |
104
|
|
|
if ($familyName === false) { |
105
|
|
|
$family_name2 = 'Not Set'; |
106
|
|
|
} else { |
107
|
|
|
$family_name2 = $result->family_name; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$Email = (isset($result->email) ? $result->email : false); |
111
|
|
|
if ($Email === false) { |
112
|
|
|
$email2 = 'Not Set'; |
113
|
|
|
} else { |
114
|
|
|
$email2 = $result->email; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$display_name = (isset($result->displayName) ? $result->displayName : false); |
118
|
|
|
if ($display_name === false) { |
119
|
|
|
$displayName2 = 'Not Set'; |
120
|
|
|
} else { |
121
|
|
|
$displayName2 = $result->displayName; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
$Gender = (isset($result->gender) ? $result->gender : false); |
125
|
|
|
if ($Gender === false) { |
126
|
|
|
$gender2 = 'Not Set'; |
127
|
|
|
} else { |
128
|
|
|
$gender2 = $result->gender; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
$phone_number = (isset($result->phone_number) ? $result->phone_number : false); |
132
|
|
|
if ($phone_number === false) { |
133
|
|
|
$phoneNumber2 = 'Not Set'; |
134
|
|
|
} else { |
135
|
|
|
$phoneNumber2 = $result->phone_number; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
$birth_date = (isset($result->birthdate) ? $result->birthdate : false); |
139
|
|
|
if ($birth_date === false) { |
140
|
|
|
$birthdate2 = 'Not Set'; |
141
|
|
|
} else { |
142
|
|
|
$birthdate2 = $result->birthdate; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
$json_address = (isset($result->address) ? $result->address : false); |
146
|
|
|
if ($json_address === false) { |
147
|
|
|
$streetAddress2 = 'Not Set'; |
148
|
|
|
$townCity2 = 'Not Set'; |
149
|
|
|
$region2 = 'Not Set'; |
150
|
|
|
$postalCode2 = 'Not Set'; |
151
|
|
|
$country2 = 'Not Set'; |
152
|
|
|
} else { |
153
|
|
|
$jsonAddress = $result->address; |
154
|
|
|
|
155
|
|
|
$decodeAddress = json_decode($jsonAddress); |
156
|
|
|
|
157
|
|
|
$street_address = (isset($decodeAddress->street_address) ? $decodeAddress->street_address : false); |
158
|
|
|
if ($street_address === false) { |
159
|
|
|
$streetAddress2 = 'Not Set'; |
160
|
|
|
} else { |
161
|
|
|
$streetAddress2 = $decodeAddress->street_address; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
$town_city = (isset($decodeAddress->locality) ? $decodeAddress->locality : false); |
165
|
|
|
if ($town_city === false) { |
166
|
|
|
$townCity2 = 'Not Set'; |
167
|
|
|
} else { |
168
|
|
|
$townCity2 = $decodeAddress->locality; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
$Region = (isset($decodeAddress->region) ? $decodeAddress->region : false); |
172
|
|
|
if ($Region === false) { |
173
|
|
|
$region2 = 'Not Set'; |
174
|
|
|
} else { |
175
|
|
|
$region2 = $decodeAddress->region; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
$postal_code = (isset($decodeAddress->postal_code) ? $decodeAddress->postal_code : false); |
179
|
|
|
if ($postal_code === false) { |
180
|
|
|
$postalCode2 = 'Not Set'; |
181
|
|
|
} else { |
182
|
|
|
$postalCode2 = $decodeAddress->postal_code; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
$Country = (isset($decodeAddress->country) ? $decodeAddress->country : false); |
186
|
|
|
if ($Country === false) { |
187
|
|
|
$country2 = 'Not Set'; |
188
|
|
|
} else { |
189
|
|
|
$country2 = $decodeAddress->country; |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
$sub = (string)$sub2; |
194
|
|
|
$given_name = (string)$given_name2; |
195
|
|
|
$family_name = (string)$family_name2; |
196
|
|
|
$email = (string)$email2; |
197
|
|
|
$displayName = (string)$displayName2; |
198
|
|
|
$gender = (string)$gender2; |
199
|
|
|
$phoneNumber = (string)$phoneNumber2; |
200
|
|
|
$birthdate = (string)$birthdate2; |
201
|
|
|
$streetAddress = (string)$streetAddress2; |
202
|
|
|
$townCity = (string)$townCity2; |
203
|
|
|
$region = (string)$region2; |
204
|
|
|
$postalCode = (string)$postalCode2; |
205
|
|
|
$country = (string)$country2; |
206
|
|
|
|
207
|
|
|
$newResult = array( |
208
|
|
|
"sub" => $sub , |
209
|
|
|
"given_name" => $given_name, |
210
|
|
|
"family_name" => $family_name, |
211
|
|
|
"email" => $email , |
212
|
|
|
"display_name" => $displayName, |
213
|
|
|
"gender" => $gender , |
214
|
|
|
"phone_number" => $phoneNumber, |
215
|
|
|
"birthdate" => $birthdate , |
216
|
|
|
"street_address" => $streetAddress, |
217
|
|
|
"town_city" => $townCity, |
218
|
|
|
"region" => $region, |
219
|
|
|
"postal_code" => $postalCode, |
220
|
|
|
"country" => $country, |
221
|
|
|
); |
222
|
|
|
|
223
|
|
|
$encodeNewResult = json_encode($newResult); |
224
|
|
|
$decodeNewResult = json_decode($encodeNewResult); |
225
|
|
|
|
226
|
|
|
|
227
|
|
|
|
228
|
|
|
$hydrator = new ObjectMap( |
229
|
|
|
[ |
230
|
|
|
'sub' => 'id', |
231
|
|
|
'given_name' => 'firstname', |
232
|
|
|
'family_name' => 'lastname', |
233
|
|
|
'email' => 'email', |
234
|
|
|
'display_name' => 'fullname', |
235
|
|
|
'gender' => 'gender', |
236
|
|
|
'phone_number' => 'phone', |
237
|
|
|
'birthdate' => 'birthdate', |
238
|
|
|
'street_address' => 'address', |
239
|
|
|
'town_city' => 'townCity', |
240
|
|
|
'region' => 'region', |
241
|
|
|
'postal_code' => 'postalCode', |
242
|
|
|
'country' => 'country' |
243
|
|
|
] |
244
|
|
|
); |
245
|
|
|
|
246
|
|
|
return $hydrator->hydrate(new User(), $decodeNewResult); |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
|
A high number of execution paths generally suggests many nested conditional statements and make the code less readible. This can usually be fixed by splitting the method into several smaller methods.
You can also find more information in the “Code” section of your repository.