3 final class PhabricatorOAuthResponse
extends AphrontResponse
{
9 private $errorDescription;
11 private function getState() {
14 public function setState($state) {
15 $this->state
= $state;
19 private function getContent() {
20 return $this->content
;
22 public function setContent($content) {
23 $this->content
= $content;
27 private function getClientURI() {
28 return $this->clientURI
;
30 public function setClientURI(PhutilURI
$uri) {
31 $this->setHTTPResponseCode(302);
32 $this->clientURI
= $uri;
35 private function getFullURI() {
36 $base_uri = $this->getClientURI();
37 $query_params = $this->buildResponseDict();
38 foreach ($query_params as $key => $value) {
39 $base_uri->replaceQueryParam($key, $value);
44 private function getError() {
48 public function setError($error) {
49 // errors sometimes redirect to the client (302) but otherwise
50 // the spec says all code 400
51 if (!$this->getClientURI()) {
52 $this->setHTTPResponseCode(400);
54 $this->error
= $error;
58 private function getErrorDescription() {
59 return $this->errorDescription
;
62 public function setErrorDescription($error_description) {
63 $this->errorDescription
= $error_description;
67 public function __construct() {
68 $this->setHTTPResponseCode(200); // assume the best
71 public function getHeaders() {
73 array('Content-Type', 'application/json'),
75 if ($this->getClientURI()) {
76 $headers[] = array('Location', $this->getFullURI());
78 // TODO -- T844 set headers with X-Auth-Scopes, etc
79 $headers = array_merge(parent
::getHeaders(), $headers);
83 private function buildResponseDict() {
84 if ($this->getError()) {
86 'error' => $this->getError(),
87 'error_description' => $this->getErrorDescription(),
89 $this->setContent($content);
92 $content = $this->getContent();
96 if ($this->getState()) {
97 $content['state'] = $this->getState();
102 public function buildResponseString() {
103 return $this->encodeJSONForHTTPResponse($this->buildResponseDict());