Page MenuHomePhabricator

D9761.diff
No OneTemporary

D9761.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -99,6 +99,7 @@
'PhutilAuthAdapterOAuth1' => 'auth/PhutilAuthAdapterOAuth1.php',
'PhutilAuthAdapterOAuthAmazon' => 'auth/PhutilAuthAdapterOAuthAmazon.php',
'PhutilAuthAdapterOAuthAsana' => 'auth/PhutilAuthAdapterOAuthAsana.php',
+ 'PhutilAuthAdapterOAuthBitbucket' => 'auth/PhutilAuthAdapterOAuthBitbucket.php',
'PhutilAuthAdapterOAuthDisqus' => 'auth/PhutilAuthAdapterOAuthDisqus.php',
'PhutilAuthAdapterOAuthFacebook' => 'auth/PhutilAuthAdapterOAuthFacebook.php',
'PhutilAuthAdapterOAuthGitHub' => 'auth/PhutilAuthAdapterOAuthGitHub.php',
@@ -528,6 +529,7 @@
'PhutilAuthAdapterOAuth1' => 'PhutilAuthAdapter',
'PhutilAuthAdapterOAuthAmazon' => 'PhutilAuthAdapterOAuth',
'PhutilAuthAdapterOAuthAsana' => 'PhutilAuthAdapterOAuth',
+ 'PhutilAuthAdapterOAuthBitbucket' => 'PhutilAuthAdapterOAuth1',
'PhutilAuthAdapterOAuthDisqus' => 'PhutilAuthAdapterOAuth',
'PhutilAuthAdapterOAuthFacebook' => 'PhutilAuthAdapterOAuth',
'PhutilAuthAdapterOAuthGitHub' => 'PhutilAuthAdapterOAuth',
diff --git a/src/auth/PhutilAuthAdapterOAuthBitbucket.php b/src/auth/PhutilAuthAdapterOAuthBitbucket.php
new file mode 100644
--- /dev/null
+++ b/src/auth/PhutilAuthAdapterOAuthBitbucket.php
@@ -0,0 +1,73 @@
+<?php
+
+final class PhutilAuthAdapterOAuthBitbucket extends PhutilAuthAdapterOAuth1 {
+
+ private $userInfo;
+
+ public function getAccountID() {
+ return idx($this->getUserInfo(), 'username');
+ }
+
+ public function getAccountName() {
+ return idx($this->getUserInfo(), 'display_name');
+ }
+
+ public function getAccountURI() {
+ $name = $this->getAccountName();
+ if (strlen($name)) {
+ return 'https://bitbucket.org/'.$name;
+ }
+ return null;
+ }
+
+ public function getAccountImageURI() {
+ return idx($this->getUserInfo(), 'avatar');
+ }
+
+ public function getAccountRealName() {
+ $parts = array(
+ idx($this->getUserInfo(), 'first_name'),
+ idx($this->getUserInfo(), 'last_name'),
+ );
+ $parts = array_filter($parts);
+ return implode(' ', $parts);
+ }
+
+ public function getAdapterType() {
+ return 'bitbucket';
+ }
+
+ public function getAdapterDomain() {
+ return 'bitbucket.org';
+ }
+
+ protected function getRequestTokenURI() {
+ return 'https://bitbucket.org/api/1.0/oauth/request_token';
+ }
+
+ protected function getAuthorizeTokenURI() {
+ return 'https://bitbucket.org/api/1.0/oauth/authenticate';
+ }
+
+ protected function getValidateTokenURI() {
+ return 'https://bitbucket.org/api/1.0/oauth/access_token';
+ }
+
+ private function getUserInfo() {
+ if ($this->userInfo === null) {
+ // We don't need any of the data in the handshake, but do need to
+ // finish the process. This makes sure we've completed the handshake.
+ $this->getHandshakeData();
+
+ $uri = new PhutilURI('https://bitbucket.org/api/1.0/user');
+
+ $data = $this->newOAuth1Future($uri)
+ ->setMethod('GET')
+ ->resolveJSON();
+
+ $this->userInfo = idx($data, 'user', array());
+ }
+ return $this->userInfo;
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 23, 9:07 PM (18 h, 43 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6922048
Default Alt Text
D9761.diff (3 KB)

Event Timeline