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\Core\Client\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\TokenEndpointAuthenticationMethodManager; |
19
|
|
|
|
20
|
|
|
final class TokenEndpointAuthenticationMethodEndpointRule implements Rule |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var TokenEndpointAuthenticationMethodManager |
24
|
|
|
*/ |
25
|
|
|
private $tokenEndpointAuthenticationMethodManager; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* TokenEndpointAuthenticationMethodEndpointRule constructor. |
29
|
|
|
* |
30
|
|
|
* @param TokenEndpointAuthenticationMethodManager $tokenEndpointAuthenticationMethodManager |
31
|
|
|
*/ |
32
|
|
|
public function __construct(TokenEndpointAuthenticationMethodManager $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->all()))); |
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
|
|
|
|