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() |
|
79 | |||
80 | /** |
||
81 | * Updates the current payload. |
||
82 | * |
||
83 | * @param array $payload |
||
84 | */ |
||
85 | public function setPayload(array $payload) |
||
89 | |||
90 | /** |
||
91 | * Unsupported grant type error. |
||
92 | * |
||
93 | * @return static |
||
94 | */ |
||
95 | 2 | public static function unsupportedGrantType() |
|
102 | |||
103 | /** |
||
104 | * Invalid request error. |
||
105 | * |
||
106 | * @param string $parameter The invalid parameter |
||
107 | * @param null|string $hint |
||
108 | * @param Throwable $previous Previous exception |
||
109 | * |
||
110 | * @return static |
||
111 | */ |
||
112 | 22 | public static function invalidRequest($parameter, $hint = null, Throwable $previous = null) |
|
120 | |||
121 | /** |
||
122 | * Invalid client error. |
||
123 | * |
||
124 | * @return static |
||
125 | */ |
||
126 | 13 | public static function invalidClient() |
|
132 | |||
133 | /** |
||
134 | * Invalid scope error. |
||
135 | * |
||
136 | * @param string $scope The bad scope |
||
137 | * @param null|string $redirectUri A HTTP URI to redirect the user back to |
||
138 | * |
||
139 | * @return static |
||
140 | */ |
||
141 | 4 | public static function invalidScope($scope, $redirectUri = null) |
|
156 | |||
157 | /** |
||
158 | * Invalid credentials error. |
||
159 | * |
||
160 | * @return static |
||
161 | */ |
||
162 | 1 | public static function invalidCredentials() |
|
166 | |||
167 | /** |
||
168 | * Server error. |
||
169 | * |
||
170 | * @param string $hint |
||
171 | * @param Throwable $previous |
||
172 | * |
||
173 | * @return static |
||
174 | * |
||
175 | * @codeCoverageIgnore |
||
176 | */ |
||
177 | public static function serverError($hint, Throwable $previous = null) |
||
190 | |||
191 | /** |
||
192 | * Invalid refresh token. |
||
193 | * |
||
194 | * @param null|string $hint |
||
195 | * @param Throwable $previous |
||
196 | * |
||
197 | * @return static |
||
198 | */ |
||
199 | 4 | public static function invalidRefreshToken($hint = null, Throwable $previous = null) |
|
203 | |||
204 | /** |
||
205 | * Access denied. |
||
206 | * |
||
207 | * @param null|string $hint |
||
208 | * @param null|string $redirectUri |
||
209 | * @param Throwable $previous |
||
210 | * |
||
211 | * @return static |
||
212 | */ |
||
213 | 14 | public static function accessDenied($hint = null, $redirectUri = null, Throwable $previous = null) |
|
225 | |||
226 | /** |
||
227 | * Invalid grant. |
||
228 | * |
||
229 | * @param string $hint |
||
230 | * |
||
231 | * @return static |
||
232 | */ |
||
233 | 1 | public static function invalidGrant($hint = '') |
|
245 | |||
246 | /** |
||
247 | * @return string |
||
248 | */ |
||
249 | 2 | public function getErrorType() |
|
253 | |||
254 | /** |
||
255 | * Generate a HTTP response. |
||
256 | * |
||
257 | * @param ResponseInterface $response |
||
258 | * @param bool $useFragment True if errors should be in the URI fragment instead of query string |
||
259 | * @param int $jsonOptions options passed to json_encode |
||
260 | * |
||
261 | * @return ResponseInterface |
||
262 | */ |
||
263 | 5 | public function generateHttpResponse(ResponseInterface $response, $useFragment = false, $jsonOptions = 0) |
|
287 | |||
288 | /** |
||
289 | * Get all headers that have to be send with the error response. |
||
290 | * |
||
291 | * @return array Array with header values |
||
292 | */ |
||
293 | 5 | public function getHttpHeaders() |
|
316 | |||
317 | /** |
||
318 | * Check if the exception has an associated redirect URI. |
||
319 | * |
||
320 | * Returns whether the exception includes a redirect, since |
||
321 | * getHttpStatusCode() doesn't return a 302 when there's a |
||
322 | * redirect enabled. This helps when you want to override local |
||
323 | * error pages but want to let redirects through. |
||
324 | * |
||
325 | * @return bool |
||
326 | */ |
||
327 | 2 | public function hasRedirect() |
|
331 | |||
332 | /** |
||
333 | * Returns the HTTP status code to send when the exceptions is output. |
||
334 | * |
||
335 | * @return int |
||
336 | */ |
||
337 | 5 | public function getHttpStatusCode() |
|
341 | |||
342 | /** |
||
343 | * @return null|string |
||
344 | */ |
||
345 | 14 | public function getHint() |
|
349 | } |
||
350 |