1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\modules\auth\oauth\parsers; |
4
|
|
|
|
5
|
|
|
use yii\helpers\ArrayHelper; |
6
|
|
|
use app\modules\auth\oauth\Parser; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Parser for Facebook OAuth |
10
|
|
|
*/ |
11
|
|
|
class Facebook extends Parser |
12
|
|
|
{ |
13
|
|
|
public function email(): ?string |
14
|
|
|
{ |
15
|
|
|
return ArrayHelper::getValue($this->attributes, 'email', null); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function fullName(): string |
19
|
|
|
{ |
20
|
|
|
return trim(ArrayHelper::getValue($this->attributes, 'name', '')); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function photo(): string |
24
|
|
|
{ |
25
|
|
|
$photo = ArrayHelper::getValue($this->attributes, 'picture.data.url', ''); |
26
|
|
|
|
27
|
|
|
$url = 'https://graph.facebook.com/' . $this->profileId() . '/picture?width=500&redirect=false'; |
28
|
|
|
$res = @json_decode(@file_get_contents($url)); |
29
|
|
|
|
30
|
|
|
if (is_object($res) && isset($res->data)) { |
31
|
|
|
$photo = $res->data->url; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return $photo; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function profileId(): string |
38
|
|
|
{ |
39
|
|
|
return ArrayHelper::getValue($this->attributes, 'id', ''); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function profileUrl(): string |
43
|
|
|
{ |
44
|
|
|
return ArrayHelper::getValue($this->attributes, 'link', ''); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function accessToken(): string |
48
|
|
|
{ |
49
|
|
|
return ArrayHelper::getValue($this->tokens, 'access_token', ''); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function accessTokenSecret(): string |
53
|
|
|
{ |
54
|
|
|
return ''; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|