Path: blob/master/src/applications/oauthserver/PhabricatorOAuthResponse.php
12241 views
<?php12final class PhabricatorOAuthResponse extends AphrontResponse {34private $state;5private $content;6private $clientURI;7private $error;8private $errorDescription;910private function getState() {11return $this->state;12}13public function setState($state) {14$this->state = $state;15return $this;16}1718private function getContent() {19return $this->content;20}21public function setContent($content) {22$this->content = $content;23return $this;24}2526private function getClientURI() {27return $this->clientURI;28}29public function setClientURI(PhutilURI $uri) {30$this->setHTTPResponseCode(302);31$this->clientURI = $uri;32return $this;33}34private function getFullURI() {35$base_uri = $this->getClientURI();36$query_params = $this->buildResponseDict();37foreach ($query_params as $key => $value) {38$base_uri->replaceQueryParam($key, $value);39}40return $base_uri;41}4243private function getError() {44return $this->error;45}4647public function setError($error) {48// errors sometimes redirect to the client (302) but otherwise49// the spec says all code 40050if (!$this->getClientURI()) {51$this->setHTTPResponseCode(400);52}53$this->error = $error;54return $this;55}5657private function getErrorDescription() {58return $this->errorDescription;59}6061public function setErrorDescription($error_description) {62$this->errorDescription = $error_description;63return $this;64}6566public function __construct() {67$this->setHTTPResponseCode(200); // assume the best68}6970public function getHeaders() {71$headers = array(72array('Content-Type', 'application/json'),73);74if ($this->getClientURI()) {75$headers[] = array('Location', $this->getFullURI());76}77// TODO -- T844 set headers with X-Auth-Scopes, etc78$headers = array_merge(parent::getHeaders(), $headers);79return $headers;80}8182private function buildResponseDict() {83if ($this->getError()) {84$content = array(85'error' => $this->getError(),86'error_description' => $this->getErrorDescription(),87);88$this->setContent($content);89}9091$content = $this->getContent();92if (!$content) {93return '';94}95if ($this->getState()) {96$content['state'] = $this->getState();97}98return $content;99}100101public function buildResponseString() {102return $this->encodeJSONForHTTPResponse($this->buildResponseDict());103}104105}106107108