index : flyspray | |
Archlinux32 customized Flyspray installation | gitolite user |
summaryrefslogtreecommitdiff |
author | Andreas Baumann <mail@andreasbaumann.cc> | 2020-02-01 09:05:48 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2020-02-01 09:05:48 +0100 |
commit | 6854cb3f4d8219cf1829e32122eb2502a916eae9 (patch) | |
tree | 350feb504587d932e02837a1442b059759927646 /vendor/league/oauth2-client/src/Provider/Facebook.php |
-rw-r--r-- | vendor/league/oauth2-client/src/Provider/Facebook.php | 103 |
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 @@ +<?php + +namespace League\OAuth2\Client\Provider; + +use League\OAuth2\Client\Entity\User; + +class Facebook extends AbstractProvider +{ + /** + * @const string The fallback Graph API version to use for requests. + */ + const DEFAULT_GRAPH_VERSION = 'v2.2'; + + /** + * @var string The Graph API version to use for requests. + */ + protected $graphApiVersion; + + public $scopes = ['public_profile', 'email']; + + public $responseType = 'string'; + + public function __construct($options) + { + parent::__construct($options); + $this->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]; + } +} |