commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
lib
commercetools-base
src
Client
OAuthHandlerFactory.php
1
<?php
2
3
declare(strict_types=1);
10
namespace
Commercetools\Client
;
11
12
use
Commercetools\Exception\InvalidArgumentException
;
13
use GuzzleHttp\Client;
14
use Psr\Cache\CacheItemPoolInterface;
15
use Psr\SimpleCache\CacheInterface;
16
17
class
OAuthHandlerFactory
18
{
22
public
static
function
ofAuthConfig
(
AuthConfig
$authConfig, $cache =
null
):
OAuth2Handler
23
{
24
$cache = CacheValidator::validateCache($cache);
25
switch
(
true
) {
26
case
$authConfig instanceof
ClientCredentialsConfig
:
27
$provider =
new
CachedTokenProvider
(
28
new
ClientCredentialTokenProvider
(
29
new
Client($authConfig->
getOptions
()),
30
$authConfig->
getAuthUri
(),
31
$authConfig->getCredentials()
32
),
33
$cache,
34
$authConfig->getCredentials()->getCacheKey()
35
);
36
break
;
37
default
:
38
throw
new
InvalidArgumentException
(
'Unknown authorization configuration'
);
39
}
40
return
self::ofProvider
($provider);
41
}
42
43
public
static
function
ofProvider
(
TokenProvider
$provider):
OAuth2Handler
44
{
45
return
new
OAuth2Handler
($provider);
46
}
47
}
Commercetools\Client\CachedTokenProvider
Definition:
CachedTokenProvider.php:18
Commercetools\Client\ClientCredentialTokenProvider
Definition:
ClientCredentialTokenProvider.php:15
Commercetools\Client\OAuth2Handler
Definition:
OAuth2Handler.php:16
Commercetools\Client\OAuthHandlerFactory
Definition:
OAuthHandlerFactory.php:18
Commercetools\Client\OAuthHandlerFactory\ofProvider
static ofProvider(TokenProvider $provider)
Definition:
OAuthHandlerFactory.php:43
Commercetools\Client\OAuthHandlerFactory\ofAuthConfig
static ofAuthConfig(AuthConfig $authConfig, $cache=null)
Definition:
OAuthHandlerFactory.php:22
Commercetools\Exception\InvalidArgumentException
Definition:
InvalidArgumentException.php:15
Commercetools\Client\AuthConfig
Definition:
AuthConfig.php:13
Commercetools\Client\AuthConfig\getAuthUri
getAuthUri()
Commercetools\Client\AuthConfig\getOptions
getOptions()
Commercetools\Client\ClientCredentialsConfig
Definition:
ClientCredentialsConfig.php:13
Commercetools\Client\TokenProvider
Definition:
TokenProvider.php:13
Commercetools\Client
Definition:
AnonymousFlowTokenProvider.php:5
Generated by
1.9.1