11 use OAuth\Common\Consumer\Credentials;
12 use OAuth\Common\Http\Client\ClientInterface;
13 use OAuth\Common\Http\Exception\TokenResponseException;
14 use OAuth\Common\Http\Uri\Uri;
15 use OAuth\Common\Http\Uri\UriInterface;
16 use OAuth\Common\Storage\TokenStorageInterface;
17 use OAuth\OAuth1\Service\AbstractService;
18 use OAuth\OAuth1\Signature\SignatureInterface;
19 use OAuth\OAuth1\Token\StdOAuth1Token;
20 use OAuth\OAuth1\Token\TokenInterface;
36 Credentials $credentials,
37 ClientInterface $httpClient =
null,
38 TokenStorageInterface $storage =
null,
39 SignatureInterface $signature =
null,
40 UriInterface $baseApiUri =
null 42 if (!isset($httpClient)) {
43 $httpClient = new \Magento\TestFramework\Authentication\Rest\CurlClient();
44 $httpClient->setTimeout(self::DEFAULT_TIMEOUT);
46 if (!isset($storage)) {
47 $storage = new \OAuth\Common\Storage\Memory();
49 if (!isset($signature)) {
50 $signature = new \Magento\TestFramework\Authentication\Rest\OauthClient\Signature($credentials);
52 parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri);
60 return new Uri(TESTS_BASE_URL .
'/oauth/token/request');
70 throw new \OAuth\Common\Exception\Exception(
71 'Magento REST API is 2-legged. Current operation is not available.' 82 return new Uri(TESTS_BASE_URL .
'/oauth/token/access');
93 ->getStore()->getCode();
94 return new Uri(TESTS_BASE_URL .
'/rest/' . $defaultStoreCode .
'/V1/testmodule1');
118 if (isset(
$data[
'oauth_verifier'])) {
119 $this->_oauthVerifier =
$data[
'oauth_verifier'];
134 $token =
new StdOAuth1Token();
136 $token->setRequestTokenSecret(
$data[
'oauth_token_secret']);
138 $token->setAccessTokenSecret(
$data[
'oauth_token_secret']);
139 $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
140 unset(
$data[
'oauth_token'],
$data[
'oauth_token_secret']);
154 if (!is_string($responseBody)) {
155 throw new TokenResponseException(
"Response body is expected to be a string.");
157 parse_str($responseBody,
$data);
159 throw new TokenResponseException(
'Unable to parse response.');
161 throw new TokenResponseException(
"Error occurred: '{$data['error']}'");
174 if (!isset($this->_oauthVerifier) || isEmpty($this->_oauthVerifier)) {
175 throw new TokenResponseException(
"oAuth verifier must be obtained during request token request.");
195 $this->signature->setTokenSecret(
$token->getAccessTokenSecret());
196 $parameters = $this->getBasicAuthorizationHeaderInfo();
197 if (isset($parameters[
'oauth_callback'])) {
198 unset($parameters[
'oauth_callback']);
201 $parameters = array_merge($parameters, [
'oauth_token' =>
$token->getAccessToken()]);
202 $parameters = array_merge($parameters, $bodyParams);
203 $parameters[
'oauth_signature'] = $this->signature->getSignature($uri, $parameters,
$method);
205 $authorizationHeader =
'OAuth ';
208 foreach ($parameters as $key =>
$value) {
209 $authorizationHeader .= $delimiter . rawurlencode($key) .
'="' . rawurlencode(
$value) .
'"';
213 return $authorizationHeader;
228 $uri =
new Uri($uri);
229 $tokenObj =
new StdOAuth1Token();
230 $tokenObj->setAccessToken(
$token);
231 $tokenObj->setAccessTokenSecret($tokenSecret);
232 $tokenObj->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
247 'Authorization: Bearer ' .
$token 262 $extraAuthenticationHeaders = [
'Accept' =>
'application/json'];
264 $this->signature->setTokenSecret(
$token->getAccessTokenSecret());
266 $authorizationHeader = [
275 $headers = array_merge($authorizationHeader, $extraAuthenticationHeaders);
279 return json_decode($responseBody);
getAuthorizationEndpoint()
buildOauthAuthorizationHeader($uri, $token, $tokenSecret, $bodyParams, $method='GET')
elseif(isset( $params[ 'redirect_parent']))
buildBearerTokenAuthorizationHeader($token)
parseAccessTokenResponse($responseBody)
parseRequestTokenResponse($responseBody)
validateAccessToken($token, $method='GET')
_parseResponseBody($responseBody)
__construct(Credentials $credentials, ClientInterface $httpClient=null, TokenStorageInterface $storage=null, SignatureInterface $signature=null, UriInterface $baseApiUri=null)
getRequestTokenEndpoint()
_parseToken($responseBody)
buildAuthorizationHeaderForAPIRequest( $method, UriInterface $uri, TokenInterface $token, $bodyParams=null)
static getObjectManager()