|
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\Rule; |
|
15
|
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\Server\Core\Client\ClientId; |
|
17
|
|
|
use OAuth2Framework\Component\Server\Core\Client\Rule\Rule; |
|
18
|
|
|
use OAuth2Framework\Component\Server\Core\DataBag\DataBag; |
|
19
|
|
|
use OAuth2Framework\Component\Server\Scope\Policy\ScopePolicyManager; |
|
20
|
|
|
|
|
21
|
|
|
final class ScopePolicyRule implements Rule |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var ScopePolicyManager |
|
25
|
|
|
*/ |
|
26
|
|
|
private $scopePolicyManager; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param ScopePolicyManager $scopePolicyManager |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(ScopePolicyManager $scopePolicyManager) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->scopePolicyManager = $scopePolicyManager; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* {@inheritdoc} |
|
38
|
|
|
*/ |
|
39
|
|
|
public function handle(ClientId $clientId, DataBag $commandParameters, DataBag $validatedParameters, callable $next): DataBag |
|
40
|
|
|
{ |
|
41
|
|
|
if ($commandParameters->has('scope_policy')) { |
|
42
|
|
|
$policy = $commandParameters->get('scope_policy'); |
|
43
|
|
|
if (!is_string($policy)) { |
|
44
|
|
|
throw new \InvalidArgumentException('The parameter "scope_policy" must be a string.'); |
|
45
|
|
|
} |
|
46
|
|
|
if (!$this->scopePolicyManager->has($policy)) { |
|
47
|
|
|
throw new \InvalidArgumentException(sprintf('The scope policy "%s" is not supported.', $policy)); |
|
48
|
|
|
} |
|
49
|
|
|
$validatedParameters = $validatedParameters->with('scope_policy', $commandParameters->get('scope_policy')); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return $next($clientId, $commandParameters, $validatedParameters); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|