Differential D9431 Diff 22523 src/applications/conduit/method/ConduitAPI_conduit_getcertificate_Method.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/conduit/method/ConduitAPI_conduit_getcertificate_Method.php
| Show All 9 Lines | final class ConduitAPI_conduit_getcertificate_Method extends ConduitAPIMethod { | ||||
| } | } | ||||
| public function shouldAllowUnguardedWrites() { | public function shouldAllowUnguardedWrites() { | ||||
| // This method performs logging and is on the authentication pathway. | // This method performs logging and is on the authentication pathway. | ||||
| return true; | return true; | ||||
| } | } | ||||
| public function getMethodDescription() { | public function getMethodDescription() { | ||||
| return "Retrieve certificate information for a user."; | return 'Retrieve certificate information for a user.'; | ||||
| } | } | ||||
| public function defineParamTypes() { | public function defineParamTypes() { | ||||
| return array( | return array( | ||||
| 'token' => 'required string', | 'token' => 'required string', | ||||
| 'host' => 'required string', | 'host' => 'required string', | ||||
| ); | ); | ||||
| } | } | ||||
| public function defineReturnType() { | public function defineReturnType() { | ||||
| return 'dict<string, any>'; | return 'dict<string, any>'; | ||||
| } | } | ||||
| public function defineErrorTypes() { | public function defineErrorTypes() { | ||||
| return array( | return array( | ||||
| "ERR-BAD-TOKEN" => "Token does not exist or has expired.", | 'ERR-BAD-TOKEN' => 'Token does not exist or has expired.', | ||||
| "ERR-RATE-LIMIT" => | 'ERR-RATE-LIMIT' => | ||||
| "You have made too many invalid token requests recently. Wait before ". | 'You have made too many invalid token requests recently. Wait before '. | ||||
| "making more.", | 'making more.', | ||||
| ); | ); | ||||
| } | } | ||||
| protected function execute(ConduitAPIRequest $request) { | protected function execute(ConduitAPIRequest $request) { | ||||
| $this->validateHost($request->getValue('host')); | $this->validateHost($request->getValue('host')); | ||||
| $failed_attempts = PhabricatorUserLog::loadRecentEventsFromThisIP( | $failed_attempts = PhabricatorUserLog::loadRecentEventsFromThisIP( | ||||
| PhabricatorUserLog::ACTION_CONDUIT_CERTIFICATE_FAILURE, | PhabricatorUserLog::ACTION_CONDUIT_CERTIFICATE_FAILURE, | ||||
| Show All 19 Lines | if (!$info || $info->getDateCreated() < time() - (60 * 15)) { | ||||
| PhabricatorUserLog::ACTION_CONDUIT_CERTIFICATE) | PhabricatorUserLog::ACTION_CONDUIT_CERTIFICATE) | ||||
| ->save(); | ->save(); | ||||
| } | } | ||||
| $user = id(new PhabricatorUser())->loadOneWhere( | $user = id(new PhabricatorUser())->loadOneWhere( | ||||
| 'phid = %s', | 'phid = %s', | ||||
| $info->getUserPHID()); | $info->getUserPHID()); | ||||
| if (!$user) { | if (!$user) { | ||||
| throw new Exception("Certificate token points to an invalid user!"); | throw new Exception('Certificate token points to an invalid user!'); | ||||
| } | } | ||||
| return array( | return array( | ||||
| 'username' => $user->getUserName(), | 'username' => $user->getUserName(), | ||||
| 'certificate' => $user->getConduitCertificate(), | 'certificate' => $user->getConduitCertificate(), | ||||
| ); | ); | ||||
| } | } | ||||
| Show All 12 Lines | |||||