Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/adapter/PhutilBitbucketAuthAdapter.php
12256 views
1
<?php
2
3
final class PhutilBitbucketAuthAdapter extends PhutilOAuth1AuthAdapter {
4
5
private $userInfo;
6
7
public function getAccountID() {
8
return idx($this->getUserInfo(), 'username');
9
}
10
11
public function getAccountName() {
12
return idx($this->getUserInfo(), 'display_name');
13
}
14
15
public function getAccountURI() {
16
$name = $this->getAccountID();
17
if (strlen($name)) {
18
return 'https://bitbucket.org/'.$name;
19
}
20
return null;
21
}
22
23
public function getAccountImageURI() {
24
return idx($this->getUserInfo(), 'avatar');
25
}
26
27
public function getAccountRealName() {
28
$parts = array(
29
idx($this->getUserInfo(), 'first_name'),
30
idx($this->getUserInfo(), 'last_name'),
31
);
32
$parts = array_filter($parts);
33
return implode(' ', $parts);
34
}
35
36
public function getAdapterType() {
37
return 'bitbucket';
38
}
39
40
public function getAdapterDomain() {
41
return 'bitbucket.org';
42
}
43
44
protected function getRequestTokenURI() {
45
return 'https://bitbucket.org/api/1.0/oauth/request_token';
46
}
47
48
protected function getAuthorizeTokenURI() {
49
return 'https://bitbucket.org/api/1.0/oauth/authenticate';
50
}
51
52
protected function getValidateTokenURI() {
53
return 'https://bitbucket.org/api/1.0/oauth/access_token';
54
}
55
56
private function getUserInfo() {
57
if ($this->userInfo === null) {
58
// We don't need any of the data in the handshake, but do need to
59
// finish the process. This makes sure we've completed the handshake.
60
$this->getHandshakeData();
61
62
$uri = new PhutilURI('https://bitbucket.org/api/1.0/user');
63
64
$data = $this->newOAuth1Future($uri)
65
->setMethod('GET')
66
->resolveJSON();
67
68
$this->userInfo = idx($data, 'user', array());
69
}
70
return $this->userInfo;
71
}
72
73
}
74
75