Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / auth / adapter / PhutilBitbucketAuthAdapter.php
blob1384548d5e072f0e015f28e55d54a279874f2690
1 <?php
3 final class PhutilBitbucketAuthAdapter extends PhutilOAuth1AuthAdapter {
5 private $userInfo;
7 public function getAccountID() {
8 return idx($this->getUserInfo(), 'username');
11 public function getAccountName() {
12 return idx($this->getUserInfo(), 'display_name');
15 public function getAccountURI() {
16 $name = $this->getAccountID();
17 if (strlen($name)) {
18 return 'https://bitbucket.org/'.$name;
20 return null;
23 public function getAccountImageURI() {
24 return idx($this->getUserInfo(), 'avatar');
27 public function getAccountRealName() {
28 $parts = array(
29 idx($this->getUserInfo(), 'first_name'),
30 idx($this->getUserInfo(), 'last_name'),
32 $parts = array_filter($parts);
33 return implode(' ', $parts);
36 public function getAdapterType() {
37 return 'bitbucket';
40 public function getAdapterDomain() {
41 return 'bitbucket.org';
44 protected function getRequestTokenURI() {
45 return 'https://bitbucket.org/api/1.0/oauth/request_token';
48 protected function getAuthorizeTokenURI() {
49 return 'https://bitbucket.org/api/1.0/oauth/authenticate';
52 protected function getValidateTokenURI() {
53 return 'https://bitbucket.org/api/1.0/oauth/access_token';
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();
62 $uri = new PhutilURI('https://bitbucket.org/api/1.0/user');
64 $data = $this->newOAuth1Future($uri)
65 ->setMethod('GET')
66 ->resolveJSON();
68 $this->userInfo = idx($data, 'user', array());
70 return $this->userInfo;