1 | <?php |
||
16 | class OAuthServerException extends Exception |
||
17 | { |
||
18 | /** |
||
19 | * @var int |
||
20 | */ |
||
21 | private $httpStatusCode; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private $errorType; |
||
27 | |||
28 | /** |
||
29 | * @var null|string |
||
30 | */ |
||
31 | private $hint; |
||
32 | |||
33 | /** |
||
34 | * @var null|string |
||
35 | */ |
||
36 | private $redirectUri; |
||
37 | |||
38 | /** |
||
39 | * @var array |
||
40 | */ |
||
41 | private $payload; |
||
42 | |||
43 | /** |
||
44 | * Throw a new exception. |
||
45 | * |
||
46 | * @param string $message Error message |
||
47 | * @param int $code Error code |
||
48 | * @param string $errorType Error type |
||
49 | * @param int $httpStatusCode HTTP status code to send (default = 400) |
||
50 | * @param null|string $hint A helper hint |
||
51 | * @param null|string $redirectUri A HTTP URI to redirect the user back to |
||
52 | * @param Throwable $previous Previous exception |
||
53 | */ |
||
54 | 70 | public function __construct($message, $code, $errorType, $httpStatusCode = 400, $hint = null, $redirectUri = null, Throwable $previous = null) |
|
69 | |||
70 | /** |
||
71 | * Returns the current payload. |
||
72 | * |
||
73 | * @return array |
||
74 | */ |
||
75 | 5 | public function getPayload() |
|
87 | |||
88 | /** |
||
89 | * Updates the current payload. |
||
90 | * |
||
91 | * @param array $payload |
||
92 | */ |
||
93 | public function setPayload(array $payload) |
||
97 | |||
98 | /** |
||
99 | * Unsupported grant type error. |
||
100 | * |
||
101 | * @return static |
||
102 | */ |
||
103 | 2 | public static function unsupportedGrantType() |
|
110 | |||
111 | /** |
||
112 | * Invalid request error. |
||
113 | * |
||
114 | * @param string $parameter The invalid parameter |
||
115 | * @param null|string $hint |
||
116 | * @param Throwable $previous Previous exception |
||
117 | * |
||
118 | * @return static |
||
119 | */ |
||
120 | 22 | public static function invalidRequest($parameter, $hint = null, Throwable $previous = null) |
|
128 | |||
129 | /** |
||
130 | * Invalid client error. |
||
131 | * |
||
132 | * @return static |
||
133 | */ |
||
134 | 13 | public static function invalidClient() |
|
140 | |||
141 | /** |
||
142 | * Invalid scope error. |
||
143 | * |
||
144 | * @param string $scope The bad scope |
||
145 | * @param null|string $redirectUri A HTTP URI to redirect the user back to |
||
146 | * |
||
147 | * @return static |
||
148 | */ |
||
149 | 4 | public static function invalidScope($scope, $redirectUri = null) |
|
164 | |||
165 | /** |
||
166 | * Invalid credentials error. |
||
167 | * |
||
168 | * @return static |
||
169 | */ |
||
170 | 1 | public static function invalidCredentials() |
|
174 | |||
175 | /** |
||
176 | * Server error. |
||
177 | * |
||
178 | * @param string $hint |
||
179 | * @param Throwable $previous |
||
180 | * |
||
181 | * @return static |
||
182 | * |
||
183 | * @codeCoverageIgnore |
||
184 | */ |
||
185 | public static function serverError($hint, Throwable $previous = null) |
||
198 | |||
199 | /** |
||
200 | * Invalid refresh token. |
||
201 | * |
||
202 | * @param null|string $hint |
||
203 | * @param Throwable $previous |
||
204 | * |
||
205 | * @return static |
||
206 | */ |
||
207 | 4 | public static function invalidRefreshToken($hint = null, Throwable $previous = null) |
|
211 | |||
212 | /** |
||
213 | * Access denied. |
||
214 | * |
||
215 | * @param null|string $hint |
||
216 | * @param null|string $redirectUri |
||
217 | * @param Throwable $previous |
||
218 | * |
||
219 | * @return static |
||
220 | */ |
||
221 | 14 | public static function accessDenied($hint = null, $redirectUri = null, Throwable $previous = null) |
|
233 | |||
234 | /** |
||
235 | * Invalid grant. |
||
236 | * |
||
237 | * @param string $hint |
||
238 | * |
||
239 | * @return static |
||
240 | */ |
||
241 | 1 | public static function invalidGrant($hint = '') |
|
253 | |||
254 | /** |
||
255 | * @return string |
||
256 | */ |
||
257 | 2 | public function getErrorType() |
|
261 | |||
262 | /** |
||
263 | * Generate a HTTP response. |
||
264 | * |
||
265 | * @param ResponseInterface $response |
||
266 | * @param bool $useFragment True if errors should be in the URI fragment instead of query string |
||
267 | * @param int $jsonOptions options passed to json_encode |
||
268 | * |
||
269 | * @return ResponseInterface |
||
270 | */ |
||
271 | 5 | public function generateHttpResponse(ResponseInterface $response, $useFragment = false, $jsonOptions = 0) |
|
295 | |||
296 | /** |
||
297 | * Get all headers that have to be send with the error response. |
||
298 | * |
||
299 | * @return array Array with header values |
||
300 | */ |
||
301 | 5 | public function getHttpHeaders() |
|
324 | |||
325 | /** |
||
326 | * Check if the exception has an associated redirect URI. |
||
327 | * |
||
328 | * Returns whether the exception includes a redirect, since |
||
329 | * getHttpStatusCode() doesn't return a 302 when there's a |
||
330 | * redirect enabled. This helps when you want to override local |
||
331 | * error pages but want to let redirects through. |
||
332 | * |
||
333 | * @return bool |
||
334 | */ |
||
335 | 2 | public function hasRedirect() |
|
339 | |||
340 | /** |
||
341 | * Returns the HTTP status code to send when the exceptions is output. |
||
342 | * |
||
343 | * @return int |
||
344 | */ |
||
345 | 5 | public function getHttpStatusCode() |
|
349 | |||
350 | /** |
||
351 | * @return null|string |
||
352 | */ |
||
353 | 14 | public function getHint() |
|
357 | } |
||
358 |