1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 18:22:41 +01:00

Use "rest/api/3/myself" to retrieve JIRA profile details, not "rest/auth/1/session"

Summary:
Ref T13493. At time of writing, the old API method no longer functions: `1/session` does not return an `accountId` but all calls now require one.

Use the modern `3/myself` API instead. The datastructure returned by `2/user` (older appraoch) and `3/myself` (newer approach) is more or less the same, as far as I can tell.

Test Plan: Linked an account against modern-at-time-of-writing Atlassian-hosted JIRA.

Maniphest Tasks: T13493

Differential Revision: https://secure.phabricator.com/D21170
This commit is contained in:
epriestley 2020-04-25 13:58:08 -07:00
parent 40d2346f29
commit a226d74133

View file

@ -10,7 +10,6 @@ final class PhutilJIRAAuthAdapter extends PhutilOAuth1AuthAdapter {
private $jiraBaseURI; private $jiraBaseURI;
private $adapterDomain; private $adapterDomain;
private $currentSession;
private $userInfo; private $userInfo;
public function setJIRABaseURI($jira_base_uri) { public function setJIRABaseURI($jira_base_uri) {
@ -106,23 +105,36 @@ final class PhutilJIRAAuthAdapter extends PhutilOAuth1AuthAdapter {
private function getUserInfo() { private function getUserInfo() {
if ($this->userInfo === null) { if ($this->userInfo === null) {
$this->currentSession = $this->newJIRAFuture('rest/auth/1/session', 'GET') $this->userInfo = $this->newUserInfo();
}
return $this->userInfo;
}
private function newUserInfo() {
// See T13493. Try a relatively modern (circa early 2020) API call first.
try {
return $this->newJIRAFuture('rest/api/3/myself', 'GET')
->resolveJSON();
} catch (Exception $ex) {
// If we failed the v3 call, assume the server version is too old
// to support this API and fall back to trying the older method.
}
$session = $this->newJIRAFuture('rest/auth/1/session', 'GET')
->resolveJSON(); ->resolveJSON();
// The session call gives us the username, but not the user key or other // The session call gives us the username, but not the user key or other
// information. Make a second call to get additional information. // information. Make a second call to get additional information.
$params = array( $params = array(
'username' => $this->currentSession['name'], 'username' => $session['name'],
); );
$this->userInfo = $this->newJIRAFuture('rest/api/2/user', 'GET', $params) return $this->newJIRAFuture('rest/api/2/user', 'GET', $params)
->resolveJSON(); ->resolveJSON();
} }
return $this->userInfo;
}
public static function newJIRAKeypair() { public static function newJIRAKeypair() {
$config = array( $config = array(
'digest_alg' => 'sha512', 'digest_alg' => 'sha512',