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\ClientAuthentication\Rule; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\ClientAuthentication\AuthenticationMethodManager; |
17
|
|
|
use OAuth2Framework\Component\ClientRule\Rule; |
18
|
|
|
use OAuth2Framework\Component\Core\Client\ClientId; |
19
|
|
|
use OAuth2Framework\Component\Core\DataBag\DataBag; |
20
|
|
|
|
21
|
|
|
class ClientAuthenticationMethodEndpointRule implements Rule |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var AuthenticationMethodManager |
25
|
|
|
*/ |
26
|
|
|
private $clientAuthenticationMethodManager; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* ClientAuthenticationMethodEndpointRule constructor. |
30
|
|
|
* |
31
|
|
|
* @param AuthenticationMethodManager $clientAuthenticationMethodManager |
32
|
|
|
*/ |
33
|
|
|
public function __construct(AuthenticationMethodManager $clientAuthenticationMethodManager) |
34
|
|
|
{ |
35
|
|
|
$this->clientAuthenticationMethodManager = $clientAuthenticationMethodManager; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
*/ |
41
|
|
|
public function handle(ClientId $clientId, DataBag $commandParameters, DataBag $validatedParameters, callable $next): DataBag |
42
|
|
|
{ |
43
|
|
|
if (!$commandParameters->has('token_endpoint_auth_method')) { |
44
|
|
|
$commandParameters = $commandParameters->with('token_endpoint_auth_method', 'client_secret_basic'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if (!is_string($commandParameters->get('token_endpoint_auth_method'))) { |
48
|
|
|
throw new \InvalidArgumentException('The parameter "token_endpoint_auth_method" must be a string.'); |
49
|
|
|
} |
50
|
|
|
if (!$this->clientAuthenticationMethodManager->has($commandParameters->get('token_endpoint_auth_method'))) { |
51
|
|
|
throw new \InvalidArgumentException(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->clientAuthenticationMethodManager->list()))); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$clientAuthenticationMethod = $this->clientAuthenticationMethodManager->get($commandParameters->get('token_endpoint_auth_method')); |
55
|
|
|
$validatedParameters = $clientAuthenticationMethod->checkClientConfiguration($commandParameters, $validatedParameters); |
56
|
|
|
|
57
|
|
|
$validatedParameters = $validatedParameters->with('token_endpoint_auth_method', $commandParameters->get('token_endpoint_auth_method')); |
58
|
|
|
|
59
|
|
|
return $next($clientId, $commandParameters, $validatedParameters); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|