1 | <?php |
||
15 | class OAuthServerException extends \Exception |
||
16 | { |
||
17 | /** |
||
18 | * @var int |
||
19 | */ |
||
20 | private $httpStatusCode; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | private $errorType; |
||
26 | |||
27 | /** |
||
28 | * @var null|string |
||
29 | */ |
||
30 | private $hint; |
||
31 | |||
32 | /** |
||
33 | * @var null|string |
||
34 | */ |
||
35 | private $redirectUri; |
||
36 | |||
37 | /** |
||
38 | * @var array |
||
39 | */ |
||
40 | private $payload; |
||
41 | |||
42 | /** |
||
43 | * @var ServerRequestInterface |
||
44 | */ |
||
45 | private $serverRequest; |
||
46 | |||
47 | /** |
||
48 | * Throw a new exception. |
||
49 | * |
||
50 | * @param string $message Error message |
||
51 | * @param int $code Error code |
||
52 | * @param string $errorType Error type |
||
53 | * @param int $httpStatusCode HTTP status code to send (default = 400) |
||
54 | * @param null|string $hint A helper hint |
||
55 | * @param null|string $redirectUri A HTTP URI to redirect the user back to |
||
56 | */ |
||
57 | 67 | public function __construct($message, $code, $errorType, $httpStatusCode = 400, $hint = null, $redirectUri = null) |
|
72 | |||
73 | /** |
||
74 | * Returns the current payload. |
||
75 | * |
||
76 | * @return array |
||
77 | */ |
||
78 | 7 | public function getPayload() |
|
82 | |||
83 | /** |
||
84 | * Updates the current payload. |
||
85 | * |
||
86 | * @param array $payload |
||
87 | */ |
||
88 | public function setPayload(array $payload) |
||
92 | |||
93 | /** |
||
94 | * Set the server request that is responsible for generating the exception |
||
95 | * |
||
96 | * @param ServerRequestInterface $serverRequest |
||
97 | */ |
||
98 | 15 | public function setServerRequest($serverRequest) |
|
102 | |||
103 | /** |
||
104 | * Unsupported grant type error. |
||
105 | * |
||
106 | * @return static |
||
107 | */ |
||
108 | 2 | public static function unsupportedGrantType() |
|
115 | |||
116 | /** |
||
117 | * Invalid request error. |
||
118 | * |
||
119 | * @param string $parameter The invalid parameter |
||
120 | * @param null|string $hint |
||
121 | * |
||
122 | * @return static |
||
123 | */ |
||
124 | 22 | public static function invalidRequest($parameter, $hint = null) |
|
132 | |||
133 | /** |
||
134 | * Invalid client error. |
||
135 | * |
||
136 | * @param ServerRequestInterface $serverRequest |
||
137 | * |
||
138 | * @return static |
||
139 | */ |
||
140 | 15 | public static function invalidClient($serverRequest) |
|
148 | |||
149 | /** |
||
150 | * Invalid scope error. |
||
151 | * |
||
152 | * @param string $scope The bad scope |
||
153 | * @param null|string $redirectUri A HTTP URI to redirect the user back to |
||
154 | * |
||
155 | * @return static |
||
156 | */ |
||
157 | 4 | public static function invalidScope($scope, $redirectUri = null) |
|
172 | |||
173 | /** |
||
174 | * Invalid credentials error. |
||
175 | * |
||
176 | * @return static |
||
177 | */ |
||
178 | 1 | public static function invalidCredentials() |
|
182 | |||
183 | /** |
||
184 | * Server error. |
||
185 | * |
||
186 | * @param string $hint |
||
187 | * |
||
188 | * @return static |
||
189 | * |
||
190 | * @codeCoverageIgnore |
||
191 | */ |
||
192 | public static function serverError($hint) |
||
202 | |||
203 | /** |
||
204 | * Invalid refresh token. |
||
205 | * |
||
206 | * @param null|string $hint |
||
207 | * |
||
208 | * @return static |
||
209 | */ |
||
210 | 4 | public static function invalidRefreshToken($hint = null) |
|
214 | |||
215 | /** |
||
216 | * Access denied. |
||
217 | * |
||
218 | * @param null|string $hint |
||
219 | * @param null|string $redirectUri |
||
220 | * |
||
221 | * @return static |
||
222 | */ |
||
223 | 9 | public static function accessDenied($hint = null, $redirectUri = null) |
|
234 | |||
235 | /** |
||
236 | * Invalid grant. |
||
237 | * |
||
238 | * @param string $hint |
||
239 | * |
||
240 | * @return static |
||
241 | */ |
||
242 | 1 | public static function invalidGrant($hint = '') |
|
254 | |||
255 | /** |
||
256 | * @return string |
||
257 | */ |
||
258 | 2 | public function getErrorType() |
|
262 | |||
263 | /** |
||
264 | * Generate a HTTP response. |
||
265 | * |
||
266 | * @param ResponseInterface $response |
||
267 | * @param bool $useFragment True if errors should be in the URI fragment instead of query string |
||
268 | * @param int $jsonOptions options passed to json_encode |
||
269 | * |
||
270 | * @return ResponseInterface |
||
271 | */ |
||
272 | 7 | public function generateHttpResponse(ResponseInterface $response, $useFragment = false, $jsonOptions = 0) |
|
296 | |||
297 | /** |
||
298 | * Get all headers that have to be send with the error response. |
||
299 | * |
||
300 | * @return array Array with header values |
||
301 | */ |
||
302 | 7 | public function getHttpHeaders() |
|
325 | |||
326 | /** |
||
327 | * Returns the HTTP status code to send when the exceptions is output. |
||
328 | * |
||
329 | * @return int |
||
330 | */ |
||
331 | 7 | public function getHttpStatusCode() |
|
335 | |||
336 | /** |
||
337 | * @return null|string |
||
338 | */ |
||
339 | 14 | public function getHint() |
|
343 | } |
||
344 |