|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Commercetools\Core\Client; |
|
4
|
|
|
|
|
5
|
|
|
use Commercetools\Core\Client\OAuth\AnonymousFlowTokenProvider; |
|
6
|
|
|
use Commercetools\Core\Client\OAuth\AnonymousIdProvider; |
|
7
|
|
|
use Commercetools\Core\Client\OAuth\ClientCredentials; |
|
8
|
|
|
use Commercetools\Core\Client\OAuth\PasswordFlowTokenProvider; |
|
9
|
|
|
use Commercetools\Core\Client\OAuth\RefreshFlowTokenProvider; |
|
10
|
|
|
use Commercetools\Core\Client\OAuth\TokenStorage; |
|
11
|
|
|
use Commercetools\Core\Client\OAuth\TokenStorageProvider; |
|
12
|
|
|
use Commercetools\Core\Config; |
|
13
|
|
|
use GuzzleHttp\Client; |
|
14
|
|
|
|
|
15
|
|
|
class ProviderFactory |
|
16
|
|
|
{ |
|
17
|
9 |
|
public function createTokenStorageProviderFor( |
|
18
|
|
|
Config $config, |
|
19
|
|
|
Client $client, |
|
20
|
|
|
TokenStorage $storage, |
|
21
|
|
|
AnonymousIdProvider $anonymousIdProvider = null |
|
22
|
|
|
) { |
|
23
|
9 |
|
return $this->createTokenStorageProvider( |
|
24
|
9 |
|
$config->getOauthUrl(Config::GRANT_TYPE_ANONYMOUS), |
|
25
|
9 |
|
$config->getOauthUrl(Config::GRANT_TYPE_REFRESH), |
|
26
|
9 |
|
$config->getClientCredentials(), |
|
27
|
|
|
$client, |
|
28
|
|
|
$storage, |
|
29
|
|
|
$anonymousIdProvider |
|
30
|
|
|
); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
9 |
|
public function createTokenStorageProvider( |
|
34
|
|
|
$anonTokenUrl, |
|
35
|
|
|
$refreshTokenUrl, |
|
36
|
|
|
ClientCredentials $credentials, |
|
37
|
|
|
Client $client, |
|
38
|
|
|
TokenStorage $storage, |
|
39
|
|
|
AnonymousIdProvider $anonymousIdProvider = null |
|
40
|
|
|
) { |
|
41
|
9 |
|
$refreshTokenProvider = $this->createRefreshFlowProvider( |
|
42
|
9 |
|
$refreshTokenUrl, |
|
43
|
|
|
$credentials, |
|
44
|
|
|
$client, |
|
45
|
|
|
$storage |
|
46
|
|
|
); |
|
47
|
9 |
|
$anonProvider = $this->createAnonymousFlowProvider( |
|
48
|
9 |
|
$anonTokenUrl, |
|
49
|
|
|
$credentials, |
|
50
|
|
|
$client, |
|
51
|
|
|
$refreshTokenProvider, |
|
52
|
|
|
$anonymousIdProvider |
|
53
|
|
|
); |
|
54
|
9 |
|
return new TokenStorageProvider($storage, $anonProvider); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
6 |
|
public function createPasswordFlowProviderFor(Config $config, Client $client, TokenStorage $storage) |
|
58
|
|
|
{ |
|
59
|
6 |
|
return $this->createPasswordFlowProvider( |
|
60
|
6 |
|
$config->getOauthUrl(Config::GRANT_TYPE_PASSWORD), |
|
61
|
6 |
|
$config->getClientCredentials(), |
|
62
|
|
|
$client, |
|
63
|
|
|
$storage |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
6 |
|
public function createPasswordFlowProvider( |
|
68
|
|
|
$passwordTokenUrl, |
|
69
|
|
|
ClientCredentials $credentials, |
|
70
|
|
|
Client $client, |
|
71
|
|
|
TokenStorage $storage |
|
72
|
|
|
) { |
|
73
|
6 |
|
return new PasswordFlowTokenProvider($client, $passwordTokenUrl, $credentials, $storage); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
9 |
|
public function createAnonymousFlowProvider( |
|
77
|
|
|
$anonTokenUrl, |
|
78
|
|
|
ClientCredentials $credentials, |
|
79
|
|
|
Client $client, |
|
80
|
|
|
RefreshFlowTokenProvider $refreshFlowTokenProvider, |
|
81
|
|
|
AnonymousIdProvider $anonymousIdProvider = null |
|
82
|
|
|
) { |
|
83
|
9 |
|
return new AnonymousFlowTokenProvider( |
|
84
|
9 |
|
$client, |
|
85
|
|
|
$anonTokenUrl, |
|
86
|
|
|
$credentials, |
|
87
|
|
|
$refreshFlowTokenProvider, |
|
88
|
|
|
$anonymousIdProvider |
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
9 |
|
public function createRefreshFlowProvider( |
|
93
|
|
|
$refreshTokenUrl, |
|
94
|
|
|
ClientCredentials $credentials, |
|
95
|
|
|
Client $client, |
|
96
|
|
|
TokenStorage $storage |
|
97
|
|
|
) { |
|
98
|
9 |
|
return new RefreshFlowTokenProvider($client, $refreshTokenUrl, $credentials, $storage); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return ProviderFactory |
|
103
|
|
|
*/ |
|
104
|
9 |
|
public static function of() |
|
105
|
|
|
{ |
|
106
|
9 |
|
return new static(); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|