Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / auth / adapter / PhutilTwitterAuthAdapter.php
blob6f738c75f6b62763176ea78e09302fe4286e49e3
1 <?php
3 /**
4 * Authentication adapter for Twitter OAuth1.
5 */
6 final class PhutilTwitterAuthAdapter extends PhutilOAuth1AuthAdapter {
8 private $userInfo;
10 public function getAccountID() {
11 return idx($this->getHandshakeData(), 'user_id');
14 public function getAccountName() {
15 return idx($this->getHandshakeData(), 'screen_name');
18 public function getAccountURI() {
19 $name = $this->getAccountName();
20 if (strlen($name)) {
21 return 'https://twitter.com/'.$name;
23 return null;
26 public function getAccountImageURI() {
27 $info = $this->getUserInfo();
28 return idx($info, 'profile_image_url');
31 public function getAccountRealName() {
32 $info = $this->getUserInfo();
33 return idx($info, 'name');
36 public function getAdapterType() {
37 return 'twitter';
40 public function getAdapterDomain() {
41 return 'twitter.com';
44 protected function getRequestTokenURI() {
45 return 'https://api.twitter.com/oauth/request_token';
48 protected function getAuthorizeTokenURI() {
49 return 'https://api.twitter.com/oauth/authorize';
52 protected function getValidateTokenURI() {
53 return 'https://api.twitter.com/oauth/access_token';
56 private function getUserInfo() {
57 if ($this->userInfo === null) {
58 $params = array(
59 'user_id' => $this->getAccountID(),
62 $uri = new PhutilURI(
63 'https://api.twitter.com/1.1/users/show.json',
64 $params);
66 $data = $this->newOAuth1Future($uri)
67 ->setMethod('GET')
68 ->resolveJSON();
70 $this->userInfo = $data;
72 return $this->userInfo;