Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15401096
D11286.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D11286.diff
View Options
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
@@ -245,6 +245,7 @@
'PhutilPerson' => 'internationalization/PhutilPerson.php',
'PhutilPersonTest' => 'internationalization/__tests__/PhutilPersonTest.php',
'PhutilPersonaAuthAdapter' => 'auth/PhutilPersonaAuthAdapter.php',
+ 'PhutilPhabricatorAuthAdapter' => 'auth/PhutilPhabricatorAuthAdapter.php',
'PhutilPhobjectTestCase' => 'object/__tests__/PhutilPhobjectTestCase.php',
'PhutilPhtTestCase' => 'internationalization/__tests__/PhutilPhtTestCase.php',
'PhutilProcessGroupDaemon' => 'daemon/torture/PhutilProcessGroupDaemon.php',
@@ -652,6 +653,7 @@
'PhutilPayPalAPIFuture' => 'FutureProxy',
'PhutilPersonTest' => 'PhutilPerson',
'PhutilPersonaAuthAdapter' => 'PhutilAuthAdapter',
+ 'PhutilPhabricatorAuthAdapter' => 'PhutilOAuthAuthAdapter',
'PhutilPhobjectTestCase' => 'PhutilTestCase',
'PhutilPhtTestCase' => 'PhutilTestCase',
'PhutilProcessGroupDaemon' => 'PhutilTortureTestDaemon',
diff --git a/src/auth/PhutilPhabricatorAuthAdapter.php b/src/auth/PhutilPhabricatorAuthAdapter.php
new file mode 100644
--- /dev/null
+++ b/src/auth/PhutilPhabricatorAuthAdapter.php
@@ -0,0 +1,100 @@
+<?php
+
+/**
+ * Authentication adapter for Phabricator OAuth2.
+ */
+final class PhutilPhabricatorAuthAdapter extends PhutilOAuthAuthAdapter {
+
+ private $phabricatorBaseURI;
+ private $adapterDomain;
+
+ public function setPhabricatorBaseURI($uri) {
+ $this->phabricatorBaseURI = $uri;
+ return $this;
+ }
+
+ public function getPhabricatorBaseURI() {
+ return $this->phabricatorBaseURI;
+ }
+
+ public function getAdapterDomain() {
+ return $this->adapterDomain;
+ }
+
+ public function setAdapterDomain($domain) {
+ $this->adapterDomain = $domain;
+ return $this;
+ }
+
+ public function getAdapterType() {
+ return 'phabricator';
+ }
+
+ public function getAccountID() {
+ return $this->getOAuthAccountData('phid');
+ }
+
+ public function getAccountEmail() {
+ return null;
+ }
+
+ public function getAccountName() {
+ return $this->getOAuthAccountData('userName');
+ }
+
+ public function getAccountImageURI() {
+ return $this->getOAuthAccountData('image');
+ }
+
+ public function getAccountURI() {
+ return $this->getOAuthAccountData('uri');
+ }
+
+ public function getAccountRealName() {
+ return $this->getOAuthAccountData('userName');
+ }
+
+ protected function getAuthenticateBaseURI() {
+ return $this->getPhabricatorURI('oauthserver/auth/');
+ }
+
+ protected function getTokenBaseURI() {
+ return $this->getPhabricatorURI('oauthserver/token/');
+ }
+
+ public function getScope() {
+ return 'whoami';
+ }
+
+ public function getExtraAuthenticateParameters() {
+ return array(
+ 'response_type' => 'code',
+ );
+ }
+
+ public function getExtraTokenParameters() {
+ return array(
+ 'grant_type' => 'authorization_code',
+ );
+ }
+
+ protected function loadOAuthAccountData() {
+ $uri = id(new PhutilURI($this->getPhabricatorURI('api/user.whoami')))
+ ->setQueryParam('access_token', $this->getAccessToken());
+ list($body) = id(new HTTPSFuture($uri))->resolvex();
+
+ $data = json_decode($body, true);
+ if (!is_array($data)) {
+ throw new Exception(
+ 'Expected valid JSON response from Phabricator user.whoami request, '.
+ 'got: '.$body);
+ }
+
+ return $data['result'];
+ }
+
+ private function getPhabricatorURI($path) {
+ return rtrim($this->phabricatorBaseURI, '/').'/'.ltrim($path, '/');
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Mar 18, 3:42 PM (15 h, 50 m ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7644409
Default Alt Text
D11286.diff (3 KB)
Attached To
Mode
D11286: OAuth - add adapter for Phabricator OAuth server
Attached
Detach File
Event Timeline
Log In to Comment