Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
17 / 17 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
|
100.00% |
17 / 17 |
|
100.00% |
6 / 6 |
6 | |
100.00% |
1 / 1 |
|
getAuthorizeUrl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getAccessTokenUrl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getScope | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getUserProfile | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
getLogoSource | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getThemeColor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace Miniframe\SocialLogin\Provider; |
4 | |
5 | use Miniframe\SocialLogin\Model\User; |
6 | |
7 | class Facebook extends AbstractOAuth2Provider |
8 | { |
9 | /** |
10 | * Returns the Authorize URL |
11 | * |
12 | * @return string |
13 | */ |
14 | protected function getAuthorizeUrl(): string |
15 | { |
16 | return 'https://www.facebook.com/v11.0/dialog/oauth'; |
17 | } |
18 | |
19 | /** |
20 | * Returns the Access Token URL |
21 | * |
22 | * @return string |
23 | */ |
24 | protected function getAccessTokenUrl(): string |
25 | { |
26 | return 'https://graph.facebook.com/v11.0/oauth/access_token'; |
27 | } |
28 | |
29 | /** |
30 | * Returns the requested scope |
31 | * |
32 | * @return string|null |
33 | */ |
34 | protected function getScope(): ?string |
35 | { |
36 | return null; |
37 | } |
38 | |
39 | /** |
40 | * Returns the user profile |
41 | * |
42 | * @param array $accessToken The access token. |
43 | * |
44 | * @return User |
45 | */ |
46 | protected function getUserProfile(array $accessToken): User |
47 | { |
48 | // Fetch user meta data |
49 | $userData = $this->curlRequest('https://graph.facebook.com/me', 'GET', null, [ |
50 | 'Authorization: Bearer ' . $accessToken['access_token'], |
51 | ]); |
52 | |
53 | // Fetch avatar meta data |
54 | $avatarData = $this->curlRequest( |
55 | 'https://graph.facebook.com/v11.0/me/picture?format=json&redirect=false&height=128&width=128', |
56 | 'GET', |
57 | null, |
58 | [ |
59 | 'Authorization: Bearer ' . $accessToken['access_token'], |
60 | 'Accept: application/json' |
61 | ] |
62 | ); |
63 | |
64 | // Fetch avatar binary; this is required because of QORS on the image URL at Facebook |
65 | $avatarBlob = $this->curlRequest($avatarData['data']['url'], 'GET', [], [ |
66 | 'Authorization: Bearer ' . $accessToken['access_token'], |
67 | ], true); |
68 | $avatarSource = 'data:' . $avatarBlob['contentType'] . ';base64,' . base64_encode($avatarBlob['responseBody']); |
69 | |
70 | return new User( |
71 | $userData['id'], |
72 | $userData['id'], |
73 | $userData['name'], |
74 | $avatarSource, |
75 | static::class, |
76 | ['accessToken' => $accessToken, 'userData' => $userData, 'avatarData' => $avatarData] |
77 | ); |
78 | } |
79 | |
80 | /** |
81 | * Returns the image source for the logo of this provider. |
82 | * |
83 | * @return string |
84 | */ |
85 | public static function getLogoSource(): string |
86 | { |
87 | return 'data:image/svg+xml;base64,' |
88 | . base64_encode(file_get_contents(__DIR__ . '/../../templates/logos/Facebook.svg')); |
89 | } |
90 | |
91 | /** |
92 | * Returns the theme color for this provider. |
93 | * |
94 | * @return string |
95 | */ |
96 | public static function getThemeColor(): string |
97 | { |
98 | return 'rgba(49,135,255,255)'; |
99 | } |
100 | } |