|
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\Response\OAuth2Exception; |
|
20
|
|
|
|
|
21
|
|
|
final class ScopeParameterChecker implements ParameterChecker |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var ScopeRepository |
|
25
|
|
|
*/ |
|
26
|
|
|
private $scopeRepository; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var null|ScopePolicyManager |
|
30
|
|
|
*/ |
|
31
|
|
|
private $scopePolicyManager; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* ScopeParameterChecker constructor. |
|
35
|
|
|
* |
|
36
|
|
|
* @param ScopeRepository $scopeRepository |
|
37
|
|
|
* @param null|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 process(Authorization $authorization, callable $next): Authorization |
|
49
|
|
|
{ |
|
50
|
|
|
try { |
|
51
|
|
|
if ($authorization->hasQueryParam('scope')) { |
|
52
|
|
|
Assertion::regex($authorization->getQueryParam('scope'), '/^[\x20\x23-\x5B\x5D-\x7E]+$/', 'Invalid characters found in the \'scope\' parameter.'); |
|
53
|
|
|
$scope = explode(' ', $authorization->getQueryParam('scope')); |
|
54
|
|
|
} else { |
|
55
|
|
|
$scope = []; |
|
56
|
|
|
} |
|
57
|
|
|
if (null !== $this->scopePolicyManager) { |
|
58
|
|
|
$scope = $this->scopePolicyManager->apply($scope, $authorization->getClient()); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
$availableScope = $this->scopeRepository->getAvailableScopesForClient($authorization->getClient()); |
|
61
|
|
|
Assertion::true($this->scopeRepository->areRequestedScopesAvailable($scope, $availableScope), sprintf('An unsupported scope was requested. Available scopes for the client are %s.', implode(', ', $availableScope))); |
|
|
|
|
|
|
62
|
|
|
$authorization = $authorization->withScopes($scope); |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
return $next($authorization); |
|
65
|
|
|
} catch (\InvalidArgumentException $e) { |
|
66
|
|
|
throw new OAuth2Exception(400, OAuth2Exception::ERROR_INVALID_SCOPE, $e->getMessage(), $authorization, $e); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: