4 * Authentication adapter for Facebook OAuth2.
6 final class PhutilFacebookAuthAdapter
extends PhutilOAuthAuthAdapter
{
8 public function getAdapterType() {
12 public function getAdapterDomain() {
13 return 'facebook.com';
16 public function getAccountID() {
17 return $this->getOAuthAccountData('id');
20 public function getAccountEmail() {
21 return $this->getOAuthAccountData('email');
24 public function getAccountName() {
25 $link = $this->getOAuthAccountData('link');
31 if (!preg_match('@/([^/]+)$@', $link, $matches)) {
38 public function getAccountImageURI() {
39 $picture = $this->getOAuthAccountData('picture');
41 $picture_data = idx($picture, 'data');
43 return idx($picture_data, 'url');
49 public function getAccountURI() {
50 return $this->getOAuthAccountData('link');
53 public function getAccountRealName() {
54 return $this->getOAuthAccountData('name');
57 protected function getAuthenticateBaseURI() {
58 return 'https://www.facebook.com/dialog/oauth';
61 protected function getTokenBaseURI() {
62 return 'https://graph.facebook.com/oauth/access_token';
65 protected function loadOAuthAccountData() {
74 $uri = new PhutilURI('https://graph.facebook.com/me');
75 $uri->replaceQueryParam('access_token', $this->getAccessToken());
76 $uri->replaceQueryParam('fields', implode(',', $fields));
77 list($body) = id(new HTTPSFuture($uri))->resolvex();
81 $data = phutil_json_decode($body);
82 } catch (PhutilJSONParserException
$ex) {
83 throw new PhutilProxyException(
84 pht('Expected valid JSON response from Facebook account data request.'),