1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright 2009 - 2019, Cake Development Corporation (https://www.cakedc.com) |
4
|
|
|
* |
5
|
|
|
* Licensed under The MIT License |
6
|
|
|
* Redistributions of files must retain the above copyright notice. |
7
|
|
|
* |
8
|
|
|
* @copyright Copyright 2009 - 2019, Cake Development Corporation (https://www.cakedc.com) |
9
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) |
10
|
|
|
*/ |
11
|
|
|
namespace CakeDC\OAuth2\Client\Provider; |
12
|
|
|
|
13
|
|
|
use League\OAuth2\Client\Provider\ResourceOwnerInterface; |
14
|
|
|
|
15
|
|
|
class CognitoUser implements ResourceOwnerInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
protected $data; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param array $response |
24
|
|
|
*/ |
25
|
2 |
|
public function __construct(array $response) |
26
|
|
|
{ |
27
|
2 |
|
$this->data = $response; |
28
|
2 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Get id |
32
|
|
|
* |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
2 |
|
public function getId() |
36
|
|
|
{ |
37
|
2 |
|
return $this->getField('sub'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get address. |
42
|
|
|
* |
43
|
|
|
* @return string|null |
44
|
|
|
*/ |
45
|
2 |
|
public function getAddress() |
46
|
|
|
{ |
47
|
2 |
|
return $this->getField('address'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get username. |
52
|
|
|
* |
53
|
|
|
* @return string|null |
54
|
|
|
*/ |
55
|
2 |
|
public function getUsername() |
56
|
|
|
{ |
57
|
2 |
|
return $this->getField('username'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get email address. |
62
|
|
|
* |
63
|
|
|
* @return string|null |
64
|
|
|
*/ |
65
|
2 |
|
public function getEmail() |
66
|
|
|
{ |
67
|
2 |
|
return $this->getField('email'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get email verified. |
72
|
|
|
* |
73
|
|
|
* @return string|null |
74
|
|
|
*/ |
75
|
2 |
|
public function getEmailVerified() |
76
|
|
|
{ |
77
|
2 |
|
return $this->getField('email_verified'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Get phone number. |
82
|
|
|
* |
83
|
|
|
* @return string|null |
84
|
|
|
*/ |
85
|
2 |
|
public function getPhoneNumber() |
86
|
|
|
{ |
87
|
2 |
|
return $this->getField('phone_number'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Get phone number verified. |
92
|
|
|
* |
93
|
|
|
* @return string|null |
94
|
|
|
*/ |
95
|
2 |
|
public function getPhoneNumberVerified() |
96
|
|
|
{ |
97
|
2 |
|
return $this->getField('phone_number_verified'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get birthdate. |
102
|
|
|
* |
103
|
|
|
* @return string|null |
104
|
|
|
*/ |
105
|
2 |
|
public function getBirthdate() |
106
|
|
|
{ |
107
|
2 |
|
return $this->getField('birthdate'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Get profile. |
112
|
|
|
* |
113
|
|
|
* @return string|null |
114
|
|
|
*/ |
115
|
2 |
|
public function getProfile() |
116
|
|
|
{ |
117
|
2 |
|
return $this->getField('profile'); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Get gender. |
122
|
|
|
* |
123
|
|
|
* @return string|null |
124
|
|
|
*/ |
125
|
2 |
|
public function getGender() |
126
|
|
|
{ |
127
|
2 |
|
return $this->getField('gender'); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Get name. |
132
|
|
|
* |
133
|
|
|
* @return string|null |
134
|
|
|
*/ |
135
|
2 |
|
public function getName() |
136
|
|
|
{ |
137
|
2 |
|
return $this->getField('name'); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Get given name. |
142
|
|
|
* |
143
|
|
|
* @return string|null |
144
|
|
|
*/ |
145
|
2 |
|
public function getGivenName() |
146
|
|
|
{ |
147
|
2 |
|
return $this->getField('given_name'); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Get middle name. |
152
|
|
|
* |
153
|
|
|
* @return string|null |
154
|
|
|
*/ |
155
|
2 |
|
public function getMiddleName() |
156
|
|
|
{ |
157
|
2 |
|
return $this->getField('middle_name'); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Get family name. |
162
|
|
|
* |
163
|
|
|
* @return string|null |
164
|
|
|
*/ |
165
|
2 |
|
public function getFamilyName() |
166
|
|
|
{ |
167
|
2 |
|
return $this->getField('family_name'); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Get locale. |
172
|
|
|
* |
173
|
|
|
* @return string|null |
174
|
|
|
*/ |
175
|
2 |
|
public function getLocale() |
176
|
|
|
{ |
177
|
2 |
|
return $this->getField('locale'); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Get zone info. |
182
|
|
|
* |
183
|
|
|
* @return string|null |
184
|
|
|
*/ |
185
|
2 |
|
public function getZoneinfo() |
186
|
|
|
{ |
187
|
2 |
|
return $this->getField('zoneinfo'); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Get preferred username. |
192
|
|
|
* |
193
|
|
|
* @return string|null |
194
|
|
|
*/ |
195
|
2 |
|
public function getPreferredUsername() |
196
|
|
|
{ |
197
|
2 |
|
return $this->getField('preferred_username'); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Get nickname. |
202
|
|
|
* |
203
|
|
|
* @return string|null |
204
|
|
|
*/ |
205
|
2 |
|
public function getNickname() |
206
|
|
|
{ |
207
|
2 |
|
return $this->getField('nickname'); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Get website. |
212
|
|
|
* |
213
|
|
|
* @return string|null |
214
|
|
|
*/ |
215
|
2 |
|
public function getWebsite() |
216
|
|
|
{ |
217
|
2 |
|
return $this->getField('website'); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Get picture. |
222
|
|
|
* |
223
|
|
|
* @return string|null |
224
|
|
|
*/ |
225
|
2 |
|
public function getPicture() |
226
|
|
|
{ |
227
|
2 |
|
return $this->getField('picture'); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Get user data as an array. |
232
|
|
|
* |
233
|
|
|
* @return array |
234
|
|
|
*/ |
235
|
2 |
|
public function toArray() |
236
|
|
|
{ |
237
|
2 |
|
return $this->data; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Returns a field from the Graph node data. |
242
|
|
|
* |
243
|
|
|
* @param string $key |
244
|
|
|
* |
245
|
|
|
* @return mixed|null |
246
|
|
|
*/ |
247
|
2 |
|
private function getField($key) |
248
|
|
|
{ |
249
|
2 |
|
return isset($this->data[$key]) ? $this->data[$key] : null; |
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
|