Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / auth / adapter / PhutilFacebookAuthAdapter.php
blob9d087bbd3767df9c69c0c73116e98183781f5f46
1 <?php
3 /**
4 * Authentication adapter for Facebook OAuth2.
5 */
6 final class PhutilFacebookAuthAdapter extends PhutilOAuthAuthAdapter {
8 public function getAdapterType() {
9 return 'facebook';
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');
26 if (!$link) {
27 return null;
30 $matches = null;
31 if (!preg_match('@/([^/]+)$@', $link, $matches)) {
32 return null;
35 return $matches[1];
38 public function getAccountImageURI() {
39 $picture = $this->getOAuthAccountData('picture');
40 if ($picture) {
41 $picture_data = idx($picture, 'data');
42 if ($picture_data) {
43 return idx($picture_data, 'url');
46 return null;
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() {
66 $fields = array(
67 'id',
68 'name',
69 'email',
70 'link',
71 'picture',
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();
79 $data = null;
80 try {
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.'),
85 $ex);
88 return $data;