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 | * Throw a new exception. |
||
38 | * |
||
39 | * @param string $message Error message |
||
40 | * @param int $code Error code |
||
41 | * @param string $errorType Error type |
||
42 | * @param int $httpStatusCode HTTP status code to send (default = 400) |
||
43 | * @param null|string $hint A helper hint |
||
44 | * @param null|string $redirectUri A HTTP URI to redirect the user back to |
||
45 | */ |
||
46 | public function __construct($message, $code, $errorType, $httpStatusCode = 400, $hint = null, $redirectUri = null) |
||
54 | |||
55 | /** |
||
56 | * Unsupported grant type error. |
||
57 | * |
||
58 | * @return static |
||
59 | */ |
||
60 | public static function unsupportedGrantType() |
||
67 | |||
68 | /** |
||
69 | * Invalid request error. |
||
70 | * |
||
71 | * @param string $parameter The invalid parameter |
||
72 | * @param string|null $hint |
||
73 | * |
||
74 | * @return static |
||
75 | */ |
||
76 | public static function invalidRequest($parameter, $hint = null) |
||
84 | |||
85 | /** |
||
86 | * Invalid client error. |
||
87 | * |
||
88 | * @return static |
||
89 | */ |
||
90 | public static function invalidClient() |
||
96 | |||
97 | /** |
||
98 | * Invalid scope error. |
||
99 | * |
||
100 | * @param string $scope The bad scope |
||
101 | * @param null|string $redirectUri A HTTP URI to redirect the user back to |
||
102 | * |
||
103 | * @return static |
||
104 | */ |
||
105 | public static function invalidScope($scope, $redirectUri = null) |
||
112 | |||
113 | /** |
||
114 | * Invalid credentials error. |
||
115 | * |
||
116 | * @return static |
||
117 | */ |
||
118 | public static function invalidCredentials() |
||
122 | |||
123 | /** |
||
124 | * Server error. |
||
125 | * |
||
126 | * @param $hint |
||
127 | * |
||
128 | * @return static |
||
129 | * |
||
130 | * @codeCoverageIgnore |
||
131 | */ |
||
132 | public static function serverError($hint) |
||
142 | |||
143 | /** |
||
144 | * Invalid refresh token. |
||
145 | * |
||
146 | * @param string|null $hint |
||
147 | * |
||
148 | * @return static |
||
149 | */ |
||
150 | public static function invalidRefreshToken($hint = null) |
||
154 | |||
155 | /** |
||
156 | * Access denied. |
||
157 | * |
||
158 | * @param string|null $hint |
||
159 | * @param string|null $redirectUri |
||
160 | * |
||
161 | * @return static |
||
162 | */ |
||
163 | public static function accessDenied($hint = null, $redirectUri = null) |
||
174 | |||
175 | /** |
||
176 | * Invalid grant. |
||
177 | * |
||
178 | * @param string $hint |
||
179 | * |
||
180 | * @return static |
||
181 | */ |
||
182 | public static function invalidGrant($hint = '') |
||
194 | |||
195 | /** |
||
196 | * @return string |
||
197 | */ |
||
198 | public function getErrorType() |
||
202 | |||
203 | /** |
||
204 | * Generate a HTTP response. |
||
205 | * |
||
206 | * @param \Psr\Http\Message\ResponseInterface $response |
||
207 | * @param bool $useFragment True if errors should be in the URI fragment instead of |
||
208 | * query string |
||
209 | * |
||
210 | * @return \Psr\Http\Message\ResponseInterface |
||
211 | */ |
||
212 | public function generateHttpResponse(ResponseInterface $response, $useFragment = false) |
||
243 | |||
244 | /** |
||
245 | * Get all headers that have to be send with the error response. |
||
246 | * |
||
247 | * @return array Array with header values |
||
248 | */ |
||
249 | public function getHttpHeaders() |
||
276 | |||
277 | /** |
||
278 | * Returns the HTTP status code to send when the exceptions is output. |
||
279 | * |
||
280 | * @return int |
||
281 | */ |
||
282 | public function getHttpStatusCode() |
||
286 | |||
287 | /** |
||
288 | * @return null|string |
||
289 | */ |
||
290 | public function getHint() |
||
294 | } |
||
295 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: