1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2017 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\Model\Client\Rule; |
15
|
|
|
|
16
|
|
|
use Assert\Assertion; |
17
|
|
|
use Jose\EncrypterInterface; |
18
|
|
|
use Jose\SignerInterface; |
19
|
|
|
use OAuth2Framework\Component\Server\Model\DataBag\DataBag; |
20
|
|
|
use OAuth2Framework\Component\Server\Model\UserAccount\UserAccountId; |
21
|
|
|
|
22
|
|
|
final class UserinfoEndpointAlgorithmsRule implements RuleInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var SignerInterface|null |
26
|
|
|
*/ |
27
|
|
|
private $signer; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var EncrypterInterface|null |
31
|
|
|
*/ |
32
|
|
|
private $encrypter; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* UserinfoEndpointAlgorithmsRule constructor. |
36
|
|
|
* |
37
|
|
|
* @param SignerInterface|null $signer |
38
|
|
|
* @param EncrypterInterface|null $encrypter |
39
|
|
|
*/ |
40
|
|
|
public function __construct(?SignerInterface $signer, ?EncrypterInterface $encrypter) |
41
|
|
|
{ |
42
|
|
|
$this->signer = $signer; |
43
|
|
|
$this->encrypter = $encrypter; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public function handle(DataBag $commandParameters, DataBag $validatedParameters, ? UserAccountId $userAccountId, callable $next): DataBag |
50
|
|
|
{ |
51
|
|
|
if ($commandParameters->has('userinfo_signed_response_alg') && null !== $this->signer) { |
52
|
|
|
Assertion::string($commandParameters['userinfo_signed_response_alg'], 'Invalid parameter \'userinfo_signed_response_alg\'. The value must be a string.'); |
53
|
|
|
Assertion::inArray($commandParameters['userinfo_signed_response_alg'], $this->signer->getSupportedSignatureAlgorithms(), sprintf('The ID Token signature response algorithm \'%s\' is not supported. Please choose one of the following algorithm: %s', $commandParameters->get('userinfo_signed_response_alg'), implode(', ', $this->signer->getSupportedSignatureAlgorithms()))); |
54
|
|
|
$validatedParameters = $validatedParameters->with('userinfo_signed_response_alg', $commandParameters['userinfo_signed_response_alg']); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if ($commandParameters->has('userinfo_encrypted_response_alg') && $commandParameters->has('userinfo_encrypted_response_enc') && null !== $this->encrypter) { |
58
|
|
|
Assertion::string($commandParameters['userinfo_encrypted_response_alg'], 'Invalid parameter \'userinfo_encrypted_response_alg\'. The value must be a string.'); |
59
|
|
|
Assertion::string($commandParameters['userinfo_encrypted_response_enc'], 'Invalid parameter \'userinfo_encrypted_response_enc\'. The value must be a string.'); |
60
|
|
|
Assertion::inArray($commandParameters['userinfo_encrypted_response_alg'], $this->encrypter->getSupportedKeyEncryptionAlgorithms(), sprintf('The ID Token content encryption algorithm \'%s\' is not supported. Please choose one of the following algorithm: %s', $commandParameters->get('userinfo_encrypted_response_alg'), implode(', ', $this->encrypter->getSupportedContentEncryptionAlgorithms()))); |
61
|
|
|
Assertion::inArray($commandParameters['userinfo_encrypted_response_enc'], $this->encrypter->getSupportedContentEncryptionAlgorithms(), sprintf('The ID Token key encryption algorithm \'%s\' is not supported. Please choose one of the following algorithm: %s', $commandParameters->get('userinfo_encrypted_response_enc'), implode(', ', $this->encrypter->getSupportedKeyEncryptionAlgorithms()))); |
62
|
|
|
$validatedParameters = $validatedParameters->with('userinfo_encrypted_response_alg', $commandParameters['userinfo_encrypted_response_alg']); |
63
|
|
|
$validatedParameters = $validatedParameters->with('userinfo_encrypted_response_enc', $commandParameters['userinfo_encrypted_response_enc']); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $next($commandParameters, $validatedParameters, $userAccountId); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|