|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* The MIT License (MIT) |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright (c) 2014-2019 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\ClientRule; |
|
15
|
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\Core\Client\ClientId; |
|
17
|
|
|
use OAuth2Framework\Component\Core\DataBag\DataBag; |
|
18
|
|
|
|
|
19
|
|
|
final class CommonParametersRule extends AbstractInternationalizedRule |
|
20
|
|
|
{ |
|
21
|
|
|
public function handle(ClientId $clientId, DataBag $commandParameters, DataBag $validatedParameters, RuleHandler $next): DataBag |
|
22
|
|
|
{ |
|
23
|
|
|
foreach ($this->getSupportedParameters() as $parameter => $closure) { |
|
24
|
|
|
$id = $this->getInternationalizedParameters($commandParameters, $parameter, $closure); |
|
25
|
|
|
foreach ($id as $k => $v) { |
|
26
|
|
|
$validatedParameters->set($k, $v); |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
return $next->handle($clientId, $commandParameters, $validatedParameters); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
private function getSupportedParameters(): array |
|
34
|
|
|
{ |
|
35
|
|
|
return [ |
|
36
|
|
|
'client_name' => function () { |
|
37
|
|
|
}, |
|
38
|
|
|
'client_uri' => $this->getUriVerificationClosure(), |
|
39
|
|
|
'logo_uri' => $this->getUriVerificationClosure(), |
|
40
|
|
|
'tos_uri' => $this->getUriVerificationClosure(), |
|
41
|
|
|
'policy_uri' => $this->getUriVerificationClosure(), |
|
42
|
|
|
]; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
private function getUriVerificationClosure(): \Closure |
|
46
|
|
|
{ |
|
47
|
|
|
return function ($k, $v) { |
|
48
|
|
|
if (false === filter_var($v, FILTER_VALIDATE_URL)) { |
|
49
|
|
|
throw new \InvalidArgumentException(\Safe\sprintf('The parameter with key "%s" is not a valid URL.', $k)); |
|
50
|
|
|
} |
|
51
|
|
|
}; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|