Path: blob/master/src/applications/oauthserver/storage/PhabricatorOAuthServerClient.php
12242 views
<?php12final class PhabricatorOAuthServerClient3extends PhabricatorOAuthServerDAO4implements5PhabricatorPolicyInterface,6PhabricatorApplicationTransactionInterface,7PhabricatorDestructibleInterface {89protected $secret;10protected $name;11protected $redirectURI;12protected $creatorPHID;13protected $isTrusted;14protected $viewPolicy;15protected $editPolicy;16protected $isDisabled;1718public function getEditURI() {19$id = $this->getID();20return "/oauthserver/edit/{$id}/";21}2223public function getViewURI() {24$id = $this->getID();25return "/oauthserver/client/view/{$id}/";26}2728public static function initializeNewClient(PhabricatorUser $actor) {29return id(new PhabricatorOAuthServerClient())30->setCreatorPHID($actor->getPHID())31->setSecret(Filesystem::readRandomCharacters(32))32->setViewPolicy(PhabricatorPolicies::POLICY_USER)33->setEditPolicy($actor->getPHID())34->setIsDisabled(0)35->setIsTrusted(0);36}3738protected function getConfiguration() {39return array(40self::CONFIG_AUX_PHID => true,41self::CONFIG_COLUMN_SCHEMA => array(42'name' => 'text255',43'secret' => 'text32',44'redirectURI' => 'text255',45'isTrusted' => 'bool',46'isDisabled' => 'bool',47),48self::CONFIG_KEY_SCHEMA => array(49'creatorPHID' => array(50'columns' => array('creatorPHID'),51),52),53) + parent::getConfiguration();54}5556public function generatePHID() {57return PhabricatorPHID::generateNewPHID(58PhabricatorOAuthServerClientPHIDType::TYPECONST);59}6061public function getURI() {62return urisprintf(63'/oauthserver/client/view/%d/',64$this->getID());65}666768/* -( PhabricatorPolicyInterface )----------------------------------------- */697071public function getCapabilities() {72return array(73PhabricatorPolicyCapability::CAN_VIEW,74PhabricatorPolicyCapability::CAN_EDIT,75);76}7778public function getPolicy($capability) {79switch ($capability) {80case PhabricatorPolicyCapability::CAN_VIEW:81return $this->getViewPolicy();82case PhabricatorPolicyCapability::CAN_EDIT:83return $this->getEditPolicy();84}85}8687public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {88return false;89}909192/* -( PhabricatorApplicationTransactionInterface )------------------------- */939495public function getApplicationTransactionEditor() {96return new PhabricatorOAuthServerEditor();97}9899public function getApplicationTransactionTemplate() {100return new PhabricatorOAuthServerTransaction();101}102103104/* -( PhabricatorDestructibleInterface )----------------------------------- */105106107public function destroyObjectPermanently(108PhabricatorDestructionEngine $engine) {109110$this->openTransaction();111$this->delete();112113$authorizations = id(new PhabricatorOAuthClientAuthorization())114->loadAllWhere('clientPHID = %s', $this->getPHID());115foreach ($authorizations as $authorization) {116$authorization->delete();117}118119$tokens = id(new PhabricatorOAuthServerAccessToken())120->loadAllWhere('clientPHID = %s', $this->getPHID());121foreach ($tokens as $token) {122$token->delete();123}124125$codes = id(new PhabricatorOAuthServerAuthorizationCode())126->loadAllWhere('clientPHID = %s', $this->getPHID());127foreach ($codes as $code) {128$code->delete();129}130131$this->saveTransaction();132133}134}135136137