1 | <?php |
||
14 | class OAuthServerException extends \Exception |
||
15 | { |
||
16 | /** |
||
17 | * @var int |
||
18 | */ |
||
19 | private $httpStatusCode; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | private $errorType; |
||
25 | |||
26 | /** |
||
27 | * @var null|string |
||
28 | */ |
||
29 | private $hint; |
||
30 | |||
31 | /** |
||
32 | * @var null|string |
||
33 | */ |
||
34 | private $redirectUri; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | private $payload; |
||
40 | |||
41 | /** |
||
42 | * Throw a new exception. |
||
43 | * |
||
44 | * @param string $message Error message |
||
45 | * @param int $code Error code |
||
46 | * @param string $errorType Error type |
||
47 | * @param int $httpStatusCode HTTP status code to send (default = 400) |
||
48 | * @param null|string $hint A helper hint |
||
49 | * @param null|string $redirectUri A HTTP URI to redirect the user back to |
||
50 | * @param \Throwable $previous Previous exception |
||
51 | */ |
||
52 | 68 | public function __construct($message, $code, $errorType, $httpStatusCode = 400, $hint = null, $redirectUri = null, \Throwable $previous = null) |
|
67 | |||
68 | /** |
||
69 | * Returns the current payload. |
||
70 | * |
||
71 | * @return array |
||
72 | */ |
||
73 | 5 | public function getPayload() |
|
77 | |||
78 | /** |
||
79 | * Updates the current payload. |
||
80 | * |
||
81 | * @param array $payload |
||
82 | */ |
||
83 | public function setPayload(array $payload) |
||
87 | |||
88 | /** |
||
89 | * Unsupported grant type error. |
||
90 | * |
||
91 | * @return static |
||
92 | */ |
||
93 | 2 | public static function unsupportedGrantType() |
|
100 | |||
101 | /** |
||
102 | * Invalid request error. |
||
103 | * |
||
104 | * @param string $parameter The invalid parameter |
||
105 | * @param null|string $hint |
||
106 | * @param \Throwable $previous Previous exception |
||
107 | * |
||
108 | * @return static |
||
109 | */ |
||
110 | 22 | public static function invalidRequest($parameter, $hint = null, \Throwable $previous = null) |
|
118 | |||
119 | /** |
||
120 | * Invalid client error. |
||
121 | * |
||
122 | * @return static |
||
123 | */ |
||
124 | 13 | public static function invalidClient() |
|
130 | |||
131 | /** |
||
132 | * Invalid scope error. |
||
133 | * |
||
134 | * @param string $scope The bad scope |
||
135 | * @param null|string $redirectUri A HTTP URI to redirect the user back to |
||
136 | * |
||
137 | * @return static |
||
138 | */ |
||
139 | 4 | public static function invalidScope($scope, $redirectUri = null) |
|
154 | |||
155 | /** |
||
156 | * Invalid credentials error. |
||
157 | * |
||
158 | * @return static |
||
159 | */ |
||
160 | 1 | public static function invalidCredentials() |
|
164 | |||
165 | /** |
||
166 | * Server error. |
||
167 | * |
||
168 | * @param string $hint |
||
169 | * @param \Throwable $previous |
||
170 | * |
||
171 | * @return static |
||
172 | * |
||
173 | * @codeCoverageIgnore |
||
174 | */ |
||
175 | public static function serverError($hint, \Throwable $previous = null) |
||
186 | |||
187 | /** |
||
188 | * Invalid refresh token. |
||
189 | * |
||
190 | * @param null|string $hint |
||
191 | * @param \Throwable $previous |
||
192 | * |
||
193 | * @return static |
||
194 | */ |
||
195 | 4 | public static function invalidRefreshToken($hint = null, \Throwable $previous = null) |
|
199 | |||
200 | /** |
||
201 | * Access denied. |
||
202 | * |
||
203 | * @param null|string $hint |
||
204 | * @param null|string $redirectUri |
||
205 | * @param \Throwable $previous |
||
206 | * |
||
207 | * @return static |
||
208 | */ |
||
209 | 12 | public static function accessDenied($hint = null, $redirectUri = null, \Throwable $previous = null) |
|
221 | |||
222 | /** |
||
223 | * Invalid grant. |
||
224 | * |
||
225 | * @param string $hint |
||
226 | * |
||
227 | * @return static |
||
228 | */ |
||
229 | 1 | public static function invalidGrant($hint = '') |
|
241 | |||
242 | /** |
||
243 | * @return string |
||
244 | */ |
||
245 | 2 | public function getErrorType() |
|
249 | |||
250 | /** |
||
251 | * Generate a HTTP response. |
||
252 | * |
||
253 | * @param ResponseInterface $response |
||
254 | * @param bool $useFragment True if errors should be in the URI fragment instead of query string |
||
255 | * @param int $jsonOptions options passed to json_encode |
||
256 | * |
||
257 | * @return ResponseInterface |
||
258 | */ |
||
259 | 5 | public function generateHttpResponse(ResponseInterface $response, $useFragment = false, $jsonOptions = 0) |
|
283 | |||
284 | /** |
||
285 | * Get all headers that have to be send with the error response. |
||
286 | * |
||
287 | * @return array Array with header values |
||
288 | */ |
||
289 | 5 | public function getHttpHeaders() |
|
312 | |||
313 | /** |
||
314 | * Check if the exception has an associated redirect URI. |
||
315 | * |
||
316 | * Returns whether the exception includes a redirect, since |
||
317 | * getHttpStatusCode() doesn't return a 302 when there's a |
||
318 | * redirect enabled. This helps when you want to override local |
||
319 | * error pages but want to let redirects through. |
||
320 | * |
||
321 | * @return bool |
||
322 | */ |
||
323 | 2 | public function hasRedirect() |
|
327 | |||
328 | /** |
||
329 | * Returns the HTTP status code to send when the exceptions is output. |
||
330 | * |
||
331 | * @return int |
||
332 | */ |
||
333 | 5 | public function getHttpStatusCode() |
|
337 | |||
338 | /** |
||
339 | * @return null|string |
||
340 | */ |
||
341 | 14 | public function getHint() |
|
345 | } |
||
346 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.