@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at upstream/main 106 lines 2.5 kB view raw
1<?php 2 3final class PhabricatorOAuthResponse extends AphrontResponse { 4 5 private $state; 6 private $content; 7 private $clientURI; 8 private $error; 9 private $errorDescription; 10 11 private function getState() { 12 return $this->state; 13 } 14 public function setState($state) { 15 $this->state = $state; 16 return $this; 17 } 18 19 private function getContent() { 20 return $this->content; 21 } 22 public function setContent($content) { 23 $this->content = $content; 24 return $this; 25 } 26 27 private function getClientURI() { 28 return $this->clientURI; 29 } 30 public function setClientURI(PhutilURI $uri) { 31 $this->setHTTPResponseCode(302); 32 $this->clientURI = $uri; 33 return $this; 34 } 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); 40 } 41 return $base_uri; 42 } 43 44 private function getError() { 45 return $this->error; 46 } 47 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); 53 } 54 $this->error = $error; 55 return $this; 56 } 57 58 private function getErrorDescription() { 59 return $this->errorDescription; 60 } 61 62 public function setErrorDescription($error_description) { 63 $this->errorDescription = $error_description; 64 return $this; 65 } 66 67 public function __construct() { 68 $this->setHTTPResponseCode(200); // assume the best 69 } 70 71 public function getHeaders() { 72 $headers = array( 73 array('Content-Type', 'application/json'), 74 ); 75 if ($this->getClientURI()) { 76 $headers[] = array('Location', $this->getFullURI()); 77 } 78 // TODO -- T844 set headers with X-Auth-Scopes, etc 79 $headers = array_merge(parent::getHeaders(), $headers); 80 return $headers; 81 } 82 83 private function buildResponseDict() { 84 if ($this->getError()) { 85 $content = array( 86 'error' => $this->getError(), 87 'error_description' => $this->getErrorDescription(), 88 ); 89 $this->setContent($content); 90 } 91 92 $content = $this->getContent(); 93 if (!$content) { 94 return ''; 95 } 96 if ($this->getState()) { 97 $content['state'] = $this->getState(); 98 } 99 return $content; 100 } 101 102 public function buildResponseString() { 103 return $this->encodeJSONForHTTPResponse($this->buildResponseDict()); 104 } 105 106}