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\Scope; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\Server\AuthorizationEndpoint\Authorization; |
17
|
|
|
use OAuth2Framework\Component\Server\AuthorizationEndpoint\ParameterChecker\ParameterChecker; |
18
|
|
|
use OAuth2Framework\Component\Server\Scope\Policy\ScopePolicyManager; |
19
|
|
|
use OAuth2Framework\Component\Server\Core\Exception\OAuth2Exception; |
20
|
|
|
|
21
|
|
|
final class ScopeParameterChecker implements ParameterChecker |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var ScopeRepository |
25
|
|
|
*/ |
26
|
|
|
private $scopeRepository; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var ScopePolicyManager |
30
|
|
|
*/ |
31
|
|
|
private $scopePolicyManager; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* ScopeParameterChecker constructor. |
35
|
|
|
* |
36
|
|
|
* @param ScopeRepository $scopeRepository |
37
|
|
|
* @param ScopePolicyManager $scopePolicyManager |
38
|
|
|
*/ |
39
|
|
|
public function __construct(ScopeRepository $scopeRepository, ScopePolicyManager $scopePolicyManager) |
40
|
|
|
{ |
41
|
|
|
$this->scopeRepository = $scopeRepository; |
42
|
|
|
$this->scopePolicyManager = $scopePolicyManager; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
public function check(Authorization $authorization): Authorization |
49
|
|
|
{ |
50
|
|
|
try { |
51
|
|
|
if ($authorization->hasQueryParam('scope')) { |
52
|
|
|
$requestedScope = $authorization->getQueryParam('scope'); |
53
|
|
|
if (1 !== preg_match('/^[\x20\x23-\x5B\x5D-\x7E]+$/', $requestedScope)) { |
54
|
|
|
throw new \InvalidArgumentException('Invalid characters found in the "scope" parameter.'); |
55
|
|
|
} |
56
|
|
|
} else { |
57
|
|
|
$requestedScope = ''; |
58
|
|
|
} |
59
|
|
|
$requestedScope = $this->scopePolicyManager->apply($requestedScope, $authorization->getClient()); |
60
|
|
|
$scopes = explode(' ', $requestedScope); |
61
|
|
|
|
62
|
|
|
$availableScope = $this->scopeRepository->getAvailableScopesForClient($authorization->getClient()); |
|
|
|
|
63
|
|
|
if (!$this->scopeRepository->areRequestedScopesAvailable($scopes, $availableScope)) { |
|
|
|
|
64
|
|
|
throw new \InvalidArgumentException(sprintf('An unsupported scope was requested. Available scopes for the client are %s.', implode(', ', $availableScope))); |
65
|
|
|
} |
66
|
|
|
$authorization = $authorization->withScopes($scope); |
|
|
|
|
67
|
|
|
|
68
|
|
|
return $authorization; |
69
|
|
|
} catch (\InvalidArgumentException $e) { |
70
|
|
|
throw new OAuth2Exception(400, OAuth2Exception::ERROR_INVALID_SCOPE, $e->getMessage(), $authorization, $e); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.