1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace rhertogh\Yii2Oauth2Server\exceptions; |
4
|
|
|
|
5
|
|
|
use League\OAuth2\Server\Exception\OAuthServerException; |
6
|
|
|
use rhertogh\Yii2Oauth2Server\interfaces\exceptions\Oauth2ServerExceptionInterface; |
7
|
|
|
|
8
|
|
|
class Oauth2ServerException extends OAuthServerException implements Oauth2ServerExceptionInterface |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Authorization not allowed. |
12
|
|
|
* @param null|string $redirectUri A HTTP URI to redirect the user back to |
13
|
|
|
* @return static |
14
|
|
|
* @since 1.0.0 |
15
|
|
|
*/ |
16
|
|
|
public static function authorizationNotAllowed($redirectUri = null) |
17
|
|
|
{ |
18
|
|
|
$errorMessage = 'Authorization not allowed.'; |
19
|
|
|
$hint = 'The user is not is not allowed to authorize the specified client.'; |
20
|
|
|
|
21
|
|
|
return new static($errorMessage, 0, 'authorization_not_allowed', 403, $hint, $redirectUri); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Unknown scope error. |
26
|
|
|
* |
27
|
|
|
* @param string $scope The bad scope |
28
|
|
|
* @param null|string $redirectUri A HTTP URI to redirect the user back to |
29
|
|
|
* |
30
|
|
|
* @return static |
31
|
|
|
*/ |
32
|
|
|
public static function unknownScope($scope, $redirectUri = null) |
33
|
|
|
{ |
34
|
|
|
$errorMessage = 'The requested scope is unknown.'; |
35
|
|
|
|
36
|
|
|
$hint = \sprintf( |
37
|
|
|
'Check the spelling of the `%s` scope or remove it from the request.', |
38
|
|
|
\htmlspecialchars($scope, ENT_QUOTES, 'UTF-8', false) |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
return new static($errorMessage, 5, 'scope_not_allowed_for_client', 403, $hint, $redirectUri); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Unauthorized scope error. |
46
|
|
|
* |
47
|
|
|
* @param string $scope The bad scope |
48
|
|
|
* @param null|string $redirectUri A HTTP URI to redirect the user back to |
49
|
|
|
* |
50
|
|
|
* @return static |
51
|
|
|
*/ |
52
|
|
|
public static function scopeNotAllowedForClient($scope, $redirectUri = null) |
53
|
|
|
{ |
54
|
|
|
$errorMessage = 'The requested scope is not allowed for the specified client.'; |
55
|
|
|
|
56
|
|
|
$hint = \sprintf( |
57
|
|
|
'Request access to the `%s` scope for the client or remove it from the request.', |
58
|
|
|
\htmlspecialchars($scope, ENT_QUOTES, 'UTF-8', false) |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
return new static($errorMessage, 5, 'scope_not_allowed_for_client', 403, $hint, $redirectUri); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|