Path: blob/master/src/applications/auth/adapter/PhutilBitbucketAuthAdapter.php
12256 views
<?php12final class PhutilBitbucketAuthAdapter extends PhutilOAuth1AuthAdapter {34private $userInfo;56public function getAccountID() {7return idx($this->getUserInfo(), 'username');8}910public function getAccountName() {11return idx($this->getUserInfo(), 'display_name');12}1314public function getAccountURI() {15$name = $this->getAccountID();16if (strlen($name)) {17return 'https://bitbucket.org/'.$name;18}19return null;20}2122public function getAccountImageURI() {23return idx($this->getUserInfo(), 'avatar');24}2526public function getAccountRealName() {27$parts = array(28idx($this->getUserInfo(), 'first_name'),29idx($this->getUserInfo(), 'last_name'),30);31$parts = array_filter($parts);32return implode(' ', $parts);33}3435public function getAdapterType() {36return 'bitbucket';37}3839public function getAdapterDomain() {40return 'bitbucket.org';41}4243protected function getRequestTokenURI() {44return 'https://bitbucket.org/api/1.0/oauth/request_token';45}4647protected function getAuthorizeTokenURI() {48return 'https://bitbucket.org/api/1.0/oauth/authenticate';49}5051protected function getValidateTokenURI() {52return 'https://bitbucket.org/api/1.0/oauth/access_token';53}5455private function getUserInfo() {56if ($this->userInfo === null) {57// We don't need any of the data in the handshake, but do need to58// finish the process. This makes sure we've completed the handshake.59$this->getHandshakeData();6061$uri = new PhutilURI('https://bitbucket.org/api/1.0/user');6263$data = $this->newOAuth1Future($uri)64->setMethod('GET')65->resolveJSON();6667$this->userInfo = idx($data, 'user', array());68}69return $this->userInfo;70}7172}737475