Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/adapter/PhutilTwitterAuthAdapter.php
12256 views
1
<?php
2
3
/**
4
* Authentication adapter for Twitter OAuth1.
5
*/
6
final 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 (strlen($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
}
76
77