1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Platine OAuth2 |
5
|
|
|
* |
6
|
|
|
* Platine OAuth2 is a library that implements the OAuth2 specification |
7
|
|
|
* |
8
|
|
|
* This content is released under the MIT License (MIT) |
9
|
|
|
* |
10
|
|
|
* Copyright (c) 2020 Platine OAuth2 |
11
|
|
|
* |
12
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
13
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
14
|
|
|
* in the Software without restriction, including without limitation the rights |
15
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
16
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
17
|
|
|
* furnished to do so, subject to the following conditions: |
18
|
|
|
* |
19
|
|
|
* The above copyright notice and this permission notice shall be included in all |
20
|
|
|
* copies or substantial portions of the Software. |
21
|
|
|
* |
22
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
23
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
24
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
25
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
26
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
27
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
28
|
|
|
* SOFTWARE. |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
declare(strict_types=1); |
32
|
|
|
|
33
|
|
|
namespace Platine\OAuth2\Exception; |
34
|
|
|
|
35
|
|
|
use Exception; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @class OAuth2Exception |
39
|
|
|
* @package Platine\OAuth2\Exception |
40
|
|
|
*/ |
41
|
|
|
class OAuth2Exception extends Exception |
42
|
|
|
{ |
43
|
|
|
/** |
44
|
|
|
* Create new instance |
45
|
|
|
* @param string $message |
46
|
|
|
* @param string $code |
47
|
|
|
*/ |
48
|
|
|
public function __construct(string $message, string $code) |
49
|
|
|
{ |
50
|
|
|
parent::__construct($message); |
51
|
|
|
$this->code = $code; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Throw exception for access denied |
56
|
|
|
* @param string $description |
57
|
|
|
* @return self |
58
|
|
|
*/ |
59
|
|
|
public static function accessDenied(string $description): self |
60
|
|
|
{ |
61
|
|
|
return new self($description, 'access_denied'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Throw exception for invalid request |
66
|
|
|
* @param string $description |
67
|
|
|
* @return self |
68
|
|
|
*/ |
69
|
|
|
public static function invalidRequest(string $description): self |
70
|
|
|
{ |
71
|
|
|
return new self($description, 'invalid_request'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Throw exception for invalid client |
76
|
|
|
* @param string $description |
77
|
|
|
* @return self |
78
|
|
|
*/ |
79
|
|
|
public static function invalidClient(string $description): self |
80
|
|
|
{ |
81
|
|
|
return new self($description, 'invalid_client'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Throw exception for invalid grant |
86
|
|
|
* @param string $description |
87
|
|
|
* @return self |
88
|
|
|
*/ |
89
|
|
|
public static function invalidGrant(string $description): self |
90
|
|
|
{ |
91
|
|
|
return new self($description, 'invalid_grant'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Throw exception for invalid scope |
96
|
|
|
* @param string $description |
97
|
|
|
* @return self |
98
|
|
|
*/ |
99
|
|
|
public static function invalidScope(string $description): self |
100
|
|
|
{ |
101
|
|
|
return new self($description, 'invalid_scope'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Throw exception for server error |
106
|
|
|
* @param string $description |
107
|
|
|
* @return self |
108
|
|
|
*/ |
109
|
|
|
public static function serverError(string $description): self |
110
|
|
|
{ |
111
|
|
|
return new self($description, 'server_error'); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Throw exception for temporarily unavailable |
116
|
|
|
* @param string $description |
117
|
|
|
* @return self |
118
|
|
|
*/ |
119
|
|
|
public static function temporarilyUnavailable(string $description): self |
120
|
|
|
{ |
121
|
|
|
return new self($description, 'temporarily_unavailable'); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Throw exception for unauthorized client |
126
|
|
|
* @param string $description |
127
|
|
|
* @return self |
128
|
|
|
*/ |
129
|
|
|
public static function unauthorizedClient(string $description): self |
130
|
|
|
{ |
131
|
|
|
return new self($description, 'unauthorized_client'); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Throw exception for unsupported grant type |
136
|
|
|
* @param string $description |
137
|
|
|
* @return self |
138
|
|
|
*/ |
139
|
|
|
public static function unsupportedGrantType(string $description): self |
140
|
|
|
{ |
141
|
|
|
return new self($description, 'unsupported_grant_type'); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Throw exception for unsupported response type |
146
|
|
|
* @param string $description |
147
|
|
|
* @return self |
148
|
|
|
*/ |
149
|
|
|
public static function unsupportedResponseType(string $description): self |
150
|
|
|
{ |
151
|
|
|
return new self($description, 'unsupported_response_type'); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Throw exception for unsupported token type |
156
|
|
|
* @param string $description |
157
|
|
|
* @return self |
158
|
|
|
*/ |
159
|
|
|
public static function unsupportedTokenType(string $description): self |
160
|
|
|
{ |
161
|
|
|
return new self($description, 'unsupported_token_type'); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|