12 use OAuth\Common\Consumer\Credentials;
13 use Zend\Stdlib\Exception\LogicException;
35 public static function getConsumerCredentials($date =
null)
41 $consumer = $oauthService->loadConsumer(
$integration->getConsumerId());
42 $url = TESTS_BASE_URL;
43 $consumer->setCallbackUrl(
$url);
44 $consumer->setRejectedCallbackUrl(
$url);
46 $consumer->setCreatedAt($date);
50 $verifier =
$token->createVerifierToken($consumer->getId())->getVerifier();
53 'key' => $consumer->getKey(),
54 'secret' => $consumer->getSecret(),
55 'verifier' => $verifier,
56 'consumer' => $consumer,
75 $consumerCredentials = self::getConsumerCredentials();
76 $credentials =
new Credentials($consumerCredentials[
'key'], $consumerCredentials[
'secret'], TESTS_BASE_URL);
78 $requestToken = $oAuthClient->requestRequestToken();
79 $accessToken = $oAuthClient->requestAccessToken(
80 $requestToken->getRequestToken(),
81 $consumerCredentials[
'verifier'],
82 $requestToken->getRequestTokenSecret()
87 'key' => $accessToken->getAccessToken(),
88 'secret' => $accessToken->getAccessTokenSecret(),
89 'oauth_client' => $oAuthClient
109 public static function getApiAccessCredentials($resources =
null,
Integration $integrationModel =
null)
111 if (!self::$_apiCredentials) {
112 $integration = $integrationModel ===
null ? self::_createIntegration($resources) : $integrationModel;
116 $oauthService->createAccessToken(
$integration->getConsumerId());
117 $accessToken = $oauthService->getAccessToken(
$integration->getConsumerId());
119 throw new LogicException(
'Access token was not created.');
121 $consumer = $oauthService->loadConsumer(
$integration->getConsumerId());
122 $credentials =
new Credentials($consumer->getKey(), $consumer->getSecret(), TESTS_BASE_URL);
124 $oAuthClient =
new OauthClient($credentials);
126 self::$_apiCredentials = [
127 'key' => $accessToken->getToken(),
128 'secret' => $accessToken->getSecret(),
129 'oauth_client' => $oAuthClient,
141 self::$_apiCredentials =
false;
153 foreach (glob($dir .
'/*') as $object) {
175 protected static function _createIntegration($resources)
181 $params = [
'name' =>
'Integration' . microtime()];
183 if ($resources ===
null || $resources ==
'all') {
184 $params[
'all_resources'] =
true;
186 $params[
'resource'] = $resources;
192 $varPath = realpath(
BP .
'/var');
194 throw new LogicException(
"Magento cache cannot be cleared after new ACL role creation.");
196 $cachePath = $varPath .
'/cache';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
static _rmRecursive($dir, $doSaveRoot=false)
static getObjectManager()
static clearApiAccessCredentials()