1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2018 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace OAuth2Framework\Component\Server\Core\Exception; |
15
|
|
|
|
16
|
|
|
final class OAuth2Exception extends \Exception |
17
|
|
|
{ |
18
|
|
|
//Error messages from the RFC5749 |
19
|
|
|
public const ERROR_INVALID_REQUEST = 'invalid_request'; |
20
|
|
|
|
21
|
|
|
public const ERROR_INVALID_CLIENT = 'invalid_client'; |
22
|
|
|
|
23
|
|
|
public const ERROR_INVALID_GRANT = 'invalid_grant'; |
24
|
|
|
|
25
|
|
|
public const ERROR_INVALID_SCOPE = 'invalid_scope'; |
26
|
|
|
|
27
|
|
|
public const ERROR_INVALID_TOKEN = 'invalid_token'; |
28
|
|
|
|
29
|
|
|
public const ERROR_UNAUTHORIZED_CLIENT = 'unauthorized_client'; |
30
|
|
|
|
31
|
|
|
public const ERROR_UNSUPPORTED_GRANT_TYPE = 'unsupported_grant_type'; |
32
|
|
|
|
33
|
|
|
public const ERROR_ACCESS_DENIED = 'access_denied'; |
34
|
|
|
|
35
|
|
|
public const ERROR_UNSUPPORTED_RESPONSE_TYPE = 'unsupported_response_type'; |
36
|
|
|
|
37
|
|
|
public const ERROR_SERVER_ERROR = 'server_error'; |
38
|
|
|
|
39
|
|
|
public const ERROR_TEMPORARILY_UNAVAILABLE = 'temporarily_unavailable'; |
40
|
|
|
|
41
|
|
|
// Error messages from the RFC5750 |
42
|
|
|
public const ERROR_INSUFFICIENT_SCOPE = 'insufficient_scope'; |
43
|
|
|
|
44
|
|
|
//Error messages from OpenID Connect specifications |
45
|
|
|
public const ERROR_INTERACTION_REQUIRED = 'interaction_required'; |
46
|
|
|
|
47
|
|
|
public const ERROR_LOGIN_REQUIRED = 'login_required'; |
48
|
|
|
|
49
|
|
|
public const ERROR_ACCOUNT_SELECTION_REQUIRED = 'account_selection_required'; |
50
|
|
|
|
51
|
|
|
public const ERROR_CONSENT_REQUIRED = 'consent_required'; |
52
|
|
|
|
53
|
|
|
public const ERROR_INVALID_REQUEST_URI = 'invalid_request_uri'; |
54
|
|
|
|
55
|
|
|
public const ERROR_INVALID_REQUEST_OBJECT = 'invalid_request_object'; |
56
|
|
|
|
57
|
|
|
public const ERROR_REQUEST_NOT_SUPPORTED = 'request_not_supported'; |
58
|
|
|
|
59
|
|
|
public const ERROR_REQUEST_URI_NOT_SUPPORTED = 'request_uri_not_supported'; |
60
|
|
|
|
61
|
|
|
public const ERROR_REGISTRATION_NOT_SUPPORTED = 'registration_not_supported'; |
62
|
|
|
|
63
|
|
|
//Error message for server errors (codes 5xx) |
64
|
|
|
public const ERROR_INTERNAL = 'internal_server_error'; |
65
|
|
|
|
66
|
|
|
//Custom message for this library |
67
|
|
|
public const ERROR_INVALID_RESOURCE_SERVER = 'invalid_resource_server'; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var null|string |
71
|
|
|
*/ |
72
|
|
|
private $errorDescription; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* OAuth2Exception constructor. |
76
|
|
|
* |
77
|
|
|
* @param int $code |
78
|
|
|
* @param string $error |
79
|
|
|
* @param null|string $errorDescription |
80
|
|
|
* @param \Exception|null $previous |
81
|
|
|
*/ |
82
|
|
|
public function __construct(int $code, string $error, ?string $errorDescription, ? \Exception $previous = null) |
83
|
|
|
{ |
84
|
|
|
$this->errorDescription = $errorDescription; |
85
|
|
|
parent::__construct($error, $code, $previous); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
public function getData(): array |
92
|
|
|
{ |
93
|
|
|
$data = ['error' => $this->getMessage()]; |
94
|
|
|
if (null !== $this->errorDescription) { |
95
|
|
|
$data['error_description'] = $this->errorDescription; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $data; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return null|string |
103
|
|
|
*/ |
104
|
|
|
public function getErrorDescription(): ?string |
105
|
|
|
{ |
106
|
|
|
return $this->errorDescription; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|