Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistWorkflow.php
| Show First 20 Lines • Show All 318 Lines • ▼ Show 20 Lines | final public function authenticateConduit() { | ||||
| try { | try { | ||||
| if (!$credentials) { | if (!$credentials) { | ||||
| throw new Exception( | throw new Exception( | ||||
| 'Set conduit credentials with setConduitCredentials() before '. | 'Set conduit credentials with setConduitCredentials() before '. | ||||
| 'authenticating conduit!'); | 'authenticating conduit!'); | ||||
| } | } | ||||
| // If we have `token`, this server supports the simpler, new-style | |||||
| // token-based authentication. Use that instead of all the certificate | |||||
| // stuff. | |||||
| if (isset($credentials['token'])) { | |||||
| $conduit = $this->getConduit(); | |||||
| $conduit->setConduitToken($credentials['token']); | |||||
| try { | |||||
| $result = $this->getConduit()->callMethodSynchronous( | |||||
| 'user.whoami', | |||||
| array()); | |||||
| $this->userName = $result['userName']; | |||||
| $this->userPHID = $result['phid']; | |||||
| $this->conduitAuthenticated = true; | |||||
| return; | |||||
| } catch (Exception $ex) { | |||||
| $conduit->setConduitToken(null); | |||||
| throw $ex; | |||||
| } | |||||
| } | |||||
| if (empty($credentials['user'])) { | if (empty($credentials['user'])) { | ||||
| throw new ConduitClientException( | throw new ConduitClientException( | ||||
| 'ERR-INVALID-USER', | 'ERR-INVALID-USER', | ||||
| 'Empty user in credentials.'); | 'Empty user in credentials.'); | ||||
| } | } | ||||
| if (empty($credentials['certificate'])) { | if (empty($credentials['certificate'])) { | ||||
| throw new ConduitClientException( | throw new ConduitClientException( | ||||
| 'ERR-NO-CERTIFICATE', | 'ERR-NO-CERTIFICATE', | ||||
| Show All 11 Lines | try { | ||||
| 'clientVersion' => $this->getConduitVersion(), | 'clientVersion' => $this->getConduitVersion(), | ||||
| 'clientDescription' => php_uname('n').':'.$description, | 'clientDescription' => php_uname('n').':'.$description, | ||||
| 'user' => $user, | 'user' => $user, | ||||
| 'certificate' => $certificate, | 'certificate' => $certificate, | ||||
| 'host' => $this->conduitURI, | 'host' => $this->conduitURI, | ||||
| )); | )); | ||||
| } catch (ConduitClientException $ex) { | } catch (ConduitClientException $ex) { | ||||
| if ($ex->getErrorCode() == 'ERR-NO-CERTIFICATE' || | if ($ex->getErrorCode() == 'ERR-NO-CERTIFICATE' || | ||||
| $ex->getErrorCode() == 'ERR-INVALID-USER') { | $ex->getErrorCode() == 'ERR-INVALID-USER' || | ||||
| $ex->getErrorCode() == 'ERR-INVALID-AUTH') { | |||||
| $conduit_uri = $this->conduitURI; | $conduit_uri = $this->conduitURI; | ||||
| $message = | $message = | ||||
| "\n". | "\n". | ||||
| phutil_console_format( | phutil_console_format( | ||||
| 'YOU NEED TO __INSTALL A CERTIFICATE__ TO LOGIN TO PHABRICATOR'). | 'YOU NEED TO __INSTALL A CERTIFICATE__ TO LOGIN TO PHABRICATOR'). | ||||
| "\n\n". | "\n\n". | ||||
| phutil_console_format( | phutil_console_format( | ||||
| ' To do this, run: **arc install-certificate**'). | ' To do this, run: **arc install-certificate**'). | ||||
| ▲ Show 20 Lines • Show All 1,512 Lines • Show Last 20 Lines | |||||