1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace TMV\OpenIdClient\Client; |
6
|
|
|
|
7
|
|
|
use Jose\Component\Core\JWKSet; |
8
|
|
|
use Psr\Http\Client\ClientInterface as HttpClient; |
9
|
|
|
use TMV\OpenIdClient\AuthMethod\AuthMethodFactory; |
10
|
|
|
use TMV\OpenIdClient\AuthMethod\AuthMethodFactoryInterface; |
11
|
|
|
use TMV\OpenIdClient\AuthMethod\ClientSecretBasic; |
12
|
|
|
use TMV\OpenIdClient\AuthMethod\ClientSecretJwt; |
13
|
|
|
use TMV\OpenIdClient\AuthMethod\ClientSecretPost; |
14
|
|
|
use TMV\OpenIdClient\AuthMethod\None; |
15
|
|
|
use TMV\OpenIdClient\AuthMethod\PrivateKeyJwt; |
16
|
|
|
use TMV\OpenIdClient\AuthMethod\SelfSignedTLSClientAuth; |
17
|
|
|
use TMV\OpenIdClient\AuthMethod\TLSClientAuth; |
18
|
|
|
use TMV\OpenIdClient\Client\Metadata\ClientMetadataInterface; |
19
|
|
|
use TMV\OpenIdClient\Issuer\IssuerInterface; |
20
|
|
|
|
21
|
|
|
final class Client implements ClientInterface |
22
|
|
|
{ |
23
|
|
|
/** @var IssuerInterface */ |
24
|
|
|
private $issuer; |
25
|
|
|
|
26
|
|
|
/** @var ClientMetadataInterface */ |
27
|
|
|
private $metadata; |
28
|
|
|
|
29
|
|
|
/** @var JWKSet */ |
30
|
|
|
private $jwks; |
31
|
|
|
|
32
|
|
|
/** @var AuthMethodFactoryInterface */ |
33
|
|
|
private $authMethodFactory; |
34
|
|
|
|
35
|
|
|
/** @var null|HttpClient */ |
36
|
|
|
private $httpClient; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Client constructor. |
40
|
|
|
* |
41
|
|
|
* @param IssuerInterface $issuer |
42
|
|
|
* @param ClientMetadataInterface $metadata |
43
|
|
|
* @param null|JWKSet $jwks |
44
|
|
|
* @param null|AuthMethodFactoryInterface $authMethodFactory |
45
|
|
|
* @param null|HttpClient $httpClient |
46
|
|
|
*/ |
47
|
2 |
|
public function __construct( |
48
|
|
|
IssuerInterface $issuer, |
49
|
|
|
ClientMetadataInterface $metadata, |
50
|
|
|
?JWKSet $jwks = null, |
51
|
|
|
?AuthMethodFactoryInterface $authMethodFactory = null, |
52
|
|
|
?HttpClient $httpClient = null |
53
|
|
|
) { |
54
|
2 |
|
$this->issuer = $issuer; |
55
|
2 |
|
$this->metadata = $metadata; |
56
|
2 |
|
$this->jwks = $jwks ?: new JWKSet([]); |
57
|
2 |
|
$this->authMethodFactory = $authMethodFactory ?: new AuthMethodFactory([ |
58
|
1 |
|
new ClientSecretBasic(), |
59
|
1 |
|
new ClientSecretJwt(), |
60
|
1 |
|
new ClientSecretPost(), |
61
|
1 |
|
new None(), |
62
|
1 |
|
new PrivateKeyJwt(), |
63
|
1 |
|
new TLSClientAuth(), |
64
|
1 |
|
new SelfSignedTLSClientAuth(), |
65
|
|
|
]); |
66
|
2 |
|
$this->httpClient = $httpClient; |
67
|
2 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return IssuerInterface |
71
|
|
|
*/ |
72
|
2 |
|
public function getIssuer(): IssuerInterface |
73
|
|
|
{ |
74
|
2 |
|
return $this->issuer; |
75
|
|
|
} |
76
|
|
|
|
77
|
2 |
|
public function getMetadata(): ClientMetadataInterface |
78
|
|
|
{ |
79
|
2 |
|
return $this->metadata; |
80
|
|
|
} |
81
|
|
|
|
82
|
2 |
|
public function getJwks(): JWKSet |
83
|
|
|
{ |
84
|
2 |
|
return $this->jwks; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return AuthMethodFactoryInterface |
89
|
|
|
*/ |
90
|
2 |
|
public function getAuthMethodFactory(): AuthMethodFactoryInterface |
91
|
|
|
{ |
92
|
2 |
|
return $this->authMethodFactory; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function getHttpClient(): ?HttpClient |
96
|
|
|
{ |
97
|
|
|
return $this->httpClient; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|