Failed Conditions
Push — ng ( 3a2d0f...7d4708 )
by Florent
04:04
created

__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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\ClientRegistrationEndpoint\Rule;
15
16
use OAuth2Framework\Component\Server\Core\Client\ClientId;
17
use OAuth2Framework\Component\Server\Core\DataBag\DataBag;
18
use OAuth2Framework\Component\Server\TokenEndpoint\AuthenticationMethod\AuthenticationMethodManager;
19
20
final class TokenEndpointAuthenticationMethodEndpointRule implements Rule
21
{
22
    /**
23
     * @var AuthenticationMethodManager
24
     */
25
    private $tokenEndpointAuthenticationMethodManager;
26
27
    /**
28
     * TokenEndpointAuthenticationMethodEndpointRule constructor.
29
     *
30
     * @param AuthenticationMethodManager $tokenEndpointAuthenticationMethodManager
31
     */
32
    public function __construct(AuthenticationMethodManager $tokenEndpointAuthenticationMethodManager)
33
    {
34
        $this->tokenEndpointAuthenticationMethodManager = $tokenEndpointAuthenticationMethodManager;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function handle(ClientId $clientId, DataBag $commandParameters, DataBag $validatedParameters, callable $next): DataBag
41
    {
42
        if (!$commandParameters->has('token_endpoint_auth_method')) {
43
            $commandParameters = $commandParameters->with('token_endpoint_auth_method', 'client_secret_basic');
44
        }
45
        Assertion::string($commandParameters->get('token_endpoint_auth_method'), 'The parameter "token_endpoint_auth_method" must be a string.');
46
        Assertion::true($this->tokenEndpointAuthenticationMethodManager->has($commandParameters->get('token_endpoint_auth_method')), sprintf('The token endpoint authentication method "%s" is not supported. Please use one of the following values: %s', $commandParameters->get('token_endpoint_auth_method'), implode(', ', $this->tokenEndpointAuthenticationMethodManager->list())));
47
48
        $tokenEndpointAuthenticationMethod = $this->tokenEndpointAuthenticationMethodManager->get($commandParameters->get('token_endpoint_auth_method'));
49
        $validatedParameters = $tokenEndpointAuthenticationMethod->checkClientConfiguration($commandParameters, $validatedParameters);
50
51
        $validatedParameters = $validatedParameters->with('token_endpoint_auth_method', $commandParameters->get('token_endpoint_auth_method'));
52
53
        return $next($clientId, $commandParameters, $validatedParameters);
54
    }
55
}
56