|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Limoncello\OAuthServer\Exceptions; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Copyright 2015-2019 [email protected] |
|
7
|
|
|
* |
|
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
9
|
|
|
* you may not use this file except in compliance with the License. |
|
10
|
|
|
* You may obtain a copy of the License at |
|
11
|
|
|
* |
|
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
13
|
|
|
* |
|
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17
|
|
|
* See the License for the specific language governing permissions and |
|
18
|
|
|
* limitations under the License. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
use Exception; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @package Limoncello\OAuthServer |
|
25
|
|
|
*/ |
|
26
|
|
|
abstract class OAuthRedirectException extends OAuthServerException |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* Error code. |
|
30
|
|
|
* |
|
31
|
|
|
* @link https://tools.ietf.org/html/rfc6749#section-4.1.2.1 |
|
32
|
|
|
* @link https://tools.ietf.org/html/rfc6749#section-4.2.2.1 |
|
33
|
|
|
*/ |
|
34
|
|
|
const ERROR_INVALID_REQUEST = 'invalid_request'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Error code. |
|
38
|
|
|
* |
|
39
|
|
|
* @link https://tools.ietf.org/html/rfc6749#section-4.1.2.1 |
|
40
|
|
|
* @link https://tools.ietf.org/html/rfc6749#section-4.2.2.1 |
|
41
|
|
|
*/ |
|
42
|
|
|
const ERROR_UNAUTHORIZED_CLIENT = 'unauthorized_client'; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Error code. |
|
46
|
|
|
* |
|
47
|
|
|
* @link https://tools.ietf.org/html/rfc6749#section-4.1.2.1 |
|
48
|
|
|
* @link https://tools.ietf.org/html/rfc6749#section-4.2.2.1 |
|
49
|
|
|
*/ |
|
50
|
|
|
const ERROR_ACCESS_DENIED = 'access_denied'; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Error code. |
|
54
|
|
|
* |
|
55
|
|
|
* @link https://tools.ietf.org/html/rfc6749#section-4.1.2.1 |
|
56
|
|
|
* @link https://tools.ietf.org/html/rfc6749#section-4.2.2.1 |
|
57
|
|
|
*/ |
|
58
|
|
|
const ERROR_UNSUPPORTED_RESPONSE_TYPE = 'unsupported_response_type'; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Error code. |
|
62
|
|
|
* |
|
63
|
|
|
* @link https://tools.ietf.org/html/rfc6749#section-4.1.2.1 |
|
64
|
|
|
* @link https://tools.ietf.org/html/rfc6749#section-4.2.2.1 |
|
65
|
|
|
*/ |
|
66
|
|
|
const ERROR_INVALID_SCOPE = 'invalid_scope'; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Error code. |
|
70
|
|
|
* |
|
71
|
|
|
* @link https://tools.ietf.org/html/rfc6749#section-4.1.2.1 |
|
72
|
|
|
* @link https://tools.ietf.org/html/rfc6749#section-4.2.2.1 |
|
73
|
|
|
*/ |
|
74
|
|
|
const ERROR_SERVER_ERROR = 'server_error'; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Error code. |
|
78
|
|
|
* |
|
79
|
|
|
* @link https://tools.ietf.org/html/rfc6749#section-4.1.2.1 |
|
80
|
|
|
* @link https://tools.ietf.org/html/rfc6749#section-4.2.2.1 |
|
81
|
|
|
*/ |
|
82
|
|
|
const ERROR_TEMPORARILY_UNAVAILABLE = 'temporarily_unavailable'; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Default error messages. The actual messages should be defined in child classes. |
|
86
|
|
|
* |
|
87
|
|
|
* @link https://tools.ietf.org/html/rfc6749#section-4.1.2.1 |
|
88
|
|
|
* @link https://tools.ietf.org/html/rfc6749#section-4.2.2.1 |
|
89
|
|
|
*/ |
|
90
|
|
|
const DEFAULT_MESSAGES = null; |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @var string |
|
94
|
|
|
*/ |
|
95
|
|
|
private $errorCode; |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @var string |
|
99
|
|
|
*/ |
|
100
|
|
|
private $redirectUri; |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @var string|null |
|
104
|
|
|
*/ |
|
105
|
|
|
private $errorUri; |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @var null|string |
|
109
|
|
|
*/ |
|
110
|
|
|
private $state; |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @var string[] |
|
114
|
|
|
*/ |
|
115
|
|
|
private $httpHeaders; |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @param string $errorCode |
|
119
|
|
|
* @param string $redirectUri |
|
120
|
|
|
* @param string|null $state |
|
121
|
|
|
* @param string|null $errorUri |
|
122
|
|
|
* @param string[] $httpHeaders |
|
123
|
|
|
* @param string[]|null $descriptions |
|
124
|
6 |
|
* @param Exception|null $previous |
|
125
|
|
|
*/ |
|
126
|
|
|
public function __construct( |
|
127
|
|
|
string $errorCode, |
|
128
|
|
|
string $redirectUri, |
|
129
|
|
|
string $state = null, |
|
130
|
|
|
string $errorUri = null, |
|
131
|
|
|
array $httpHeaders = [], |
|
132
|
|
|
array $descriptions = null, |
|
133
|
6 |
|
Exception $previous = null |
|
134
|
|
|
) { |
|
135
|
6 |
|
$descriptions = $descriptions === null ? static::DEFAULT_MESSAGES : $descriptions; |
|
136
|
|
|
|
|
137
|
6 |
|
parent::__construct($descriptions[$errorCode], 0, $previous); |
|
138
|
6 |
|
|
|
139
|
6 |
|
$this->errorCode = $errorCode; |
|
140
|
6 |
|
$this->redirectUri = $redirectUri; |
|
141
|
6 |
|
$this->state = $state; |
|
142
|
|
|
$this->errorUri = $errorUri; |
|
143
|
|
|
$this->httpHeaders = $httpHeaders; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
6 |
|
* @return string |
|
148
|
|
|
*/ |
|
149
|
6 |
|
public function getErrorCode(): string |
|
150
|
|
|
{ |
|
151
|
|
|
return $this->errorCode; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
6 |
|
* @return string |
|
156
|
|
|
*/ |
|
157
|
6 |
|
public function getErrorDescription(): string |
|
158
|
|
|
{ |
|
159
|
|
|
return $this->getMessage(); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
6 |
|
* @return string |
|
164
|
|
|
*/ |
|
165
|
6 |
|
public function getRedirectUri(): string |
|
166
|
|
|
{ |
|
167
|
|
|
return $this->redirectUri; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
6 |
|
* @return string|null |
|
172
|
|
|
*/ |
|
173
|
6 |
|
public function getErrorUri(): ?string |
|
174
|
|
|
{ |
|
175
|
|
|
return $this->errorUri; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
6 |
|
* @return null|string |
|
180
|
|
|
*/ |
|
181
|
6 |
|
public function getState(): ?string |
|
182
|
|
|
{ |
|
183
|
|
|
return $this->state; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
6 |
|
* @return string[] |
|
188
|
|
|
*/ |
|
189
|
6 |
|
public function getHttpHeaders(): array |
|
190
|
|
|
{ |
|
191
|
|
|
return $this->httpHeaders; |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
|