@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3/**
4 * Authentication adapter for Twitter OAuth1.
5 */
6final class PhutilTwitterAuthAdapter extends PhutilOAuth1AuthAdapter {
7
8 private $userInfo;
9
10 public function getAccountID() {
11 return idx($this->getHandshakeData(), 'user_id');
12 }
13
14 public function getAccountName() {
15 return idx($this->getHandshakeData(), 'screen_name');
16 }
17
18 public function getAccountURI() {
19 $name = $this->getAccountName();
20 if (phutil_nonempty_string($name)) {
21 return 'https://twitter.com/'.$name;
22 }
23 return null;
24 }
25
26 public function getAccountImageURI() {
27 $info = $this->getUserInfo();
28 return idx($info, 'profile_image_url');
29 }
30
31 public function getAccountRealName() {
32 $info = $this->getUserInfo();
33 return idx($info, 'name');
34 }
35
36 public function getAdapterType() {
37 return 'twitter';
38 }
39
40 public function getAdapterDomain() {
41 return 'twitter.com';
42 }
43
44 protected function getRequestTokenURI() {
45 return 'https://api.twitter.com/oauth/request_token';
46 }
47
48 protected function getAuthorizeTokenURI() {
49 return 'https://api.twitter.com/oauth/authorize';
50 }
51
52 protected function getValidateTokenURI() {
53 return 'https://api.twitter.com/oauth/access_token';
54 }
55
56 private function getUserInfo() {
57 if ($this->userInfo === null) {
58 $params = array(
59 'user_id' => $this->getAccountID(),
60 );
61
62 $uri = new PhutilURI(
63 'https://api.twitter.com/1.1/users/show.json',
64 $params);
65
66 $data = $this->newOAuth1Future($uri)
67 ->setMethod('GET')
68 ->resolveJSON();
69
70 $this->userInfo = $data;
71 }
72 return $this->userInfo;
73 }
74
75}