|
1
|
|
|
<?php
|
|
2
|
|
|
namespace Mezon\SocialNetwork\Auth;
|
|
3
|
|
|
|
|
4
|
|
|
use Mezon\SocialNetwork\BaseAuth;
|
|
5
|
|
|
|
|
6
|
|
|
/**
|
|
7
|
|
|
* Class FacebookAuth
|
|
8
|
|
|
*
|
|
9
|
|
|
* @package Auth
|
|
10
|
|
|
* @subpackage FacebookAuth
|
|
11
|
|
|
* @author Dodonov A.A.
|
|
12
|
|
|
* @version v.1.0 (2019/08/17)
|
|
13
|
|
|
* @copyright Copyright (c) 2019, aeon.org
|
|
14
|
|
|
*/
|
|
15
|
|
|
|
|
16
|
|
|
/**
|
|
17
|
|
|
* Class provides integration with Facebook.
|
|
18
|
|
|
*
|
|
19
|
|
|
* @author Dodonov A.A.
|
|
20
|
|
|
*/
|
|
21
|
|
|
class Facebook extends BaseAuth
|
|
22
|
|
|
{
|
|
23
|
|
|
|
|
24
|
|
|
/**
|
|
25
|
|
|
* Method returns URL wich generates tokens.
|
|
26
|
|
|
*
|
|
27
|
|
|
* @return string URL
|
|
28
|
|
|
*/
|
|
29
|
|
|
public function getOauthUri(): string
|
|
30
|
|
|
{
|
|
31
|
|
|
return 'https://www.facebook.com/dialog/oauth?';
|
|
32
|
|
|
}
|
|
33
|
|
|
|
|
34
|
|
|
/**
|
|
35
|
|
|
* Method return URL wich provides user's info.
|
|
36
|
|
|
*
|
|
37
|
|
|
* @param string $token
|
|
38
|
|
|
* - Token;
|
|
39
|
|
|
* @return string URL
|
|
40
|
|
|
*/
|
|
41
|
|
|
public function getUserInfoUri(string $token = ''): string
|
|
42
|
|
|
{
|
|
43
|
|
|
return 'https://graph.facebook.com/me?';
|
|
44
|
|
|
}
|
|
45
|
|
|
|
|
46
|
|
|
/**
|
|
47
|
|
|
* Method returns.
|
|
48
|
|
|
*
|
|
49
|
|
|
* @return string URL
|
|
50
|
|
|
*/
|
|
51
|
|
|
public function getTokenUri(): string
|
|
52
|
|
|
{
|
|
53
|
|
|
return 'https://graph.facebook.com/oauth/access_token?';
|
|
54
|
|
|
}
|
|
55
|
|
|
|
|
56
|
|
|
/**
|
|
57
|
|
|
* Method returns a list of desired fields.
|
|
58
|
|
|
*
|
|
59
|
|
|
* @return string Comma separated of the desired fields.
|
|
60
|
|
|
*/
|
|
61
|
|
|
public function getDesiredFields(): string
|
|
62
|
|
|
{
|
|
63
|
|
|
return 'id,first_name,last_name,email,picture.width(120).height(120)';
|
|
64
|
|
|
}
|
|
65
|
|
|
|
|
66
|
|
|
/**
|
|
67
|
|
|
* Method dispatches user info
|
|
68
|
|
|
*
|
|
69
|
|
|
* @param array $userInfo
|
|
70
|
|
|
* User info got from social network
|
|
71
|
|
|
* @return array Dispatched user info. Must be as array with keys id, first_name, last_name, email, picture
|
|
72
|
|
|
*/
|
|
73
|
|
|
public function dispatchUserInfo(array $userInfo): array
|
|
74
|
|
|
{
|
|
75
|
|
|
$userInfo['email'] = $userInfo['email'] ?? '';
|
|
76
|
|
|
$userInfo['picture'] = $userInfo['picture']['data']['url'];
|
|
77
|
|
|
|
|
78
|
|
|
return $userInfo;
|
|
79
|
|
|
}
|
|
80
|
|
|
}
|
|
81
|
|
|
|