1 | <?php |
||
17 | class OAuthServerException extends Exception |
||
18 | { |
||
19 | /** |
||
20 | * @var int |
||
21 | */ |
||
22 | private $httpStatusCode; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | private $errorType; |
||
28 | |||
29 | /** |
||
30 | * @var null|string |
||
31 | */ |
||
32 | private $hint; |
||
33 | |||
34 | /** |
||
35 | * @var null|string |
||
36 | */ |
||
37 | private $redirectUri; |
||
38 | |||
39 | /** |
||
40 | * @var array |
||
41 | */ |
||
42 | private $payload; |
||
43 | |||
44 | /** |
||
45 | * @var ServerRequestInterface |
||
46 | */ |
||
47 | private $serverRequest; |
||
48 | |||
49 | /** |
||
50 | * Throw a new exception. |
||
51 | * |
||
52 | * @param string $message Error message |
||
53 | * @param int $code Error code |
||
54 | * @param string $errorType Error type |
||
55 | * @param int $httpStatusCode HTTP status code to send (default = 400) |
||
56 | * @param null|string $hint A helper hint |
||
57 | * @param null|string $redirectUri A HTTP URI to redirect the user back to |
||
58 | * @param Throwable $previous Previous exception |
||
59 | */ |
||
60 | 77 | public function __construct($message, $code, $errorType, $httpStatusCode = 400, $hint = null, $redirectUri = null, Throwable $previous = null) |
|
75 | |||
76 | /** |
||
77 | * Returns the current payload. |
||
78 | * |
||
79 | * @return array |
||
80 | */ |
||
81 | 7 | public function getPayload() |
|
93 | |||
94 | /** |
||
95 | * Updates the current payload. |
||
96 | * |
||
97 | * @param array $payload |
||
98 | */ |
||
99 | public function setPayload(array $payload) |
||
103 | |||
104 | /** |
||
105 | * Set the server request that is responsible for generating the exception |
||
106 | * |
||
107 | * @param ServerRequestInterface $serverRequest |
||
108 | */ |
||
109 | 16 | public function setServerRequest(ServerRequestInterface $serverRequest) |
|
113 | |||
114 | /** |
||
115 | * Unsupported grant type error. |
||
116 | * |
||
117 | * @return static |
||
118 | */ |
||
119 | 2 | public static function unsupportedGrantType() |
|
126 | |||
127 | /** |
||
128 | * Invalid request error. |
||
129 | * |
||
130 | * @param string $parameter The invalid parameter |
||
131 | * @param null|string $hint |
||
132 | * @param Throwable $previous Previous exception |
||
133 | * |
||
134 | * @return static |
||
135 | */ |
||
136 | 26 | public static function invalidRequest($parameter, $hint = null, Throwable $previous = null) |
|
144 | |||
145 | /** |
||
146 | * Invalid client error. |
||
147 | * |
||
148 | * @param ServerRequestInterface $serverRequest |
||
149 | * |
||
150 | * @return static |
||
151 | */ |
||
152 | 16 | public static function invalidClient(ServerRequestInterface $serverRequest) |
|
160 | |||
161 | /** |
||
162 | * Invalid scope error. |
||
163 | * |
||
164 | * @param string $scope The bad scope |
||
165 | * @param null|string $redirectUri A HTTP URI to redirect the user back to |
||
166 | * |
||
167 | * @return static |
||
168 | */ |
||
169 | 4 | public static function invalidScope($scope, $redirectUri = null) |
|
184 | |||
185 | /** |
||
186 | * Invalid credentials error. |
||
187 | * |
||
188 | * @return static |
||
189 | */ |
||
190 | public static function invalidCredentials() |
||
194 | |||
195 | /** |
||
196 | * Server error. |
||
197 | * |
||
198 | * @param string $hint |
||
199 | * @param Throwable $previous |
||
200 | * |
||
201 | * @return static |
||
202 | * |
||
203 | * @codeCoverageIgnore |
||
204 | */ |
||
205 | public static function serverError($hint, Throwable $previous = null) |
||
218 | |||
219 | /** |
||
220 | * Invalid refresh token. |
||
221 | * |
||
222 | * @param null|string $hint |
||
223 | * @param Throwable $previous |
||
224 | * |
||
225 | * @return static |
||
226 | */ |
||
227 | 4 | public static function invalidRefreshToken($hint = null, Throwable $previous = null) |
|
231 | |||
232 | /** |
||
233 | * Access denied. |
||
234 | * |
||
235 | * @param null|string $hint |
||
236 | * @param null|string $redirectUri |
||
237 | * @param Throwable $previous |
||
238 | * |
||
239 | * @return static |
||
240 | */ |
||
241 | 14 | public static function accessDenied($hint = null, $redirectUri = null, Throwable $previous = null) |
|
253 | |||
254 | /** |
||
255 | * Invalid grant. |
||
256 | * |
||
257 | * @param string $hint |
||
258 | * |
||
259 | * @return static |
||
260 | */ |
||
261 | 2 | public static function invalidGrant($hint = '') |
|
273 | |||
274 | /** |
||
275 | * Expired token error. |
||
276 | * |
||
277 | * @param null|string $hint |
||
278 | * @param Throwable $previous Previous exception |
||
279 | * |
||
280 | * @return static |
||
281 | */ |
||
282 | public static function expiredToken($hint = null, Throwable $previous = null) |
||
288 | |||
289 | /** |
||
290 | * Authorization pending. |
||
291 | * |
||
292 | * @param string $hint |
||
293 | * |
||
294 | * @return static |
||
295 | */ |
||
296 | public static function authorizationPending($hint = '') |
||
307 | |||
308 | /** |
||
309 | * @return string |
||
310 | */ |
||
311 | 2 | public function getErrorType() |
|
315 | |||
316 | /** |
||
317 | * Generate a HTTP response. |
||
318 | * |
||
319 | * @param ResponseInterface $response |
||
320 | * @param bool $useFragment True if errors should be in the URI fragment instead of query string |
||
321 | * @param int $jsonOptions options passed to json_encode |
||
322 | * |
||
323 | * @return ResponseInterface |
||
324 | */ |
||
325 | 7 | public function generateHttpResponse(ResponseInterface $response, $useFragment = false, $jsonOptions = 0) |
|
351 | |||
352 | /** |
||
353 | * Get all headers that have to be send with the error response. |
||
354 | * |
||
355 | * @return array Array with header values |
||
356 | */ |
||
357 | 7 | public function getHttpHeaders() |
|
380 | |||
381 | /** |
||
382 | * Check if the exception has an associated redirect URI. |
||
383 | * |
||
384 | * Returns whether the exception includes a redirect, since |
||
385 | * getHttpStatusCode() doesn't return a 302 when there's a |
||
386 | * redirect enabled. This helps when you want to override local |
||
387 | * error pages but want to let redirects through. |
||
388 | * |
||
389 | * @return bool |
||
390 | */ |
||
391 | 2 | public function hasRedirect() |
|
395 | |||
396 | /** |
||
397 | * Returns the HTTP status code to send when the exceptions is output. |
||
398 | * |
||
399 | * @return int |
||
400 | */ |
||
401 | 7 | public function getHttpStatusCode() |
|
405 | |||
406 | /** |
||
407 | * @return null|string |
||
408 | */ |
||
409 | 15 | public function getHint() |
|
413 | } |
||
414 |