From 6854cb3f4d8219cf1829e32122eb2502a916eae9 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 1 Feb 2020 09:05:48 +0100 Subject: initial checkin --- .../league/oauth2-client/src/Provider/Facebook.php | 103 +++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 vendor/league/oauth2-client/src/Provider/Facebook.php (limited to 'vendor/league/oauth2-client/src/Provider/Facebook.php') diff --git a/vendor/league/oauth2-client/src/Provider/Facebook.php b/vendor/league/oauth2-client/src/Provider/Facebook.php new file mode 100644 index 0000000..9155836 --- /dev/null +++ b/vendor/league/oauth2-client/src/Provider/Facebook.php @@ -0,0 +1,103 @@ +graphApiVersion = (isset($options['graphApiVersion'])) + ? $options['graphApiVersion'] + : static::DEFAULT_GRAPH_VERSION; + } + + public function urlAuthorize() + { + return 'https://www.facebook.com/'.$this->graphApiVersion.'/dialog/oauth'; + } + + public function urlAccessToken() + { + return 'https://graph.facebook.com/'.$this->graphApiVersion.'/oauth/access_token'; + } + + public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token) + { + $fields = implode(',', [ + 'id', + 'name', + 'first_name', + 'last_name', + 'email', + 'hometown', + 'bio', + 'picture.type(large){url}', + 'gender', + 'locale', + 'link', + ]); + + return 'https://graph.facebook.com/'.$this->graphApiVersion.'/me?fields='.$fields.'&access_token='.$token; + } + + public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token) + { + $user = new User(); + + $email = (isset($response->email)) ? $response->email : null; + // The "hometown" field will only be returned if you ask for the `user_hometown` permission. + $location = (isset($response->hometown->name)) ? $response->hometown->name : null; + $description = (isset($response->bio)) ? $response->bio : null; + $imageUrl = (isset($response->picture->data->url)) ? $response->picture->data->url : null; + $gender = (isset($response->gender)) ? $response->gender : null; + $locale = (isset($response->locale)) ? $response->locale : null; + + $user->exchangeArray([ + 'uid' => $response->id, + 'name' => $response->name, + 'firstname' => $response->first_name, + 'lastname' => $response->last_name, + 'email' => $email, + 'location' => $location, + 'description' => $description, + 'imageurl' => $imageUrl, + 'gender' => $gender, + 'locale' => $locale, + 'urls' => [ 'Facebook' => $response->link ], + ]); + + return $user; + } + + public function userUid($response, \League\OAuth2\Client\Token\AccessToken $token) + { + return $response->id; + } + + public function userEmail($response, \League\OAuth2\Client\Token\AccessToken $token) + { + return isset($response->email) && $response->email ? $response->email : null; + } + + public function userScreenName($response, \League\OAuth2\Client\Token\AccessToken $token) + { + return [$response->first_name, $response->last_name]; + } +} -- cgit v1.2.3-70-g09d2