Skip to content

Commit b412ae0

Browse files
committed
ACP2E-2969: REST API unable to make requests with slash (/) in SKU when using Oauth1
1 parent 11953da commit b412ae0

File tree

3 files changed

+31
-38
lines changed

3 files changed

+31
-38
lines changed

dev/tests/api-functional/framework/Magento/TestFramework/Authentication/Rest/OauthClient.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\TestFramework\Authentication\Rest;
88

9+
use Magento\Framework\Oauth\Helper\Utility;
910
use Magento\TestFramework\Helper\Bootstrap;
1011
use OAuth\Common\Consumer\Credentials;
1112
use OAuth\Common\Http\Client\ClientInterface;
@@ -37,13 +38,15 @@ class OauthClient extends AbstractService
3738
* @param TokenStorageInterface|null $storage
3839
* @param SignatureInterface|null $signature
3940
* @param UriInterface|null $baseApiUri
41+
* @param Utility|null $helper
4042
*/
4143
public function __construct(
4244
Credentials $credentials,
4345
ClientInterface $httpClient = null,
4446
TokenStorageInterface $storage = null,
4547
SignatureInterface $signature = null,
46-
UriInterface $baseApiUri = null
48+
UriInterface $baseApiUri = null,
49+
Utility $helper = null
4750
) {
4851
if (!isset($httpClient)) {
4952
$httpClient = new \Magento\TestFramework\Authentication\Rest\CurlClient();
@@ -52,8 +55,11 @@ public function __construct(
5255
if (!isset($storage)) {
5356
$storage = new \OAuth\Common\Storage\Memory();
5457
}
58+
if (!isset($helper)) {
59+
$helper = new Utility();
60+
}
5561
if (!isset($signature)) {
56-
$signature = new \Magento\TestFramework\Authentication\Rest\OauthClient\Signature($credentials);
62+
$signature = new \Magento\TestFramework\Authentication\Rest\OauthClient\Signature($helper, $credentials);
5763
}
5864
parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri);
5965
}

dev/tests/api-functional/framework/Magento/TestFramework/Authentication/Rest/OauthClient/Signature.php

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,29 @@
66

77
namespace Magento\TestFramework\Authentication\Rest\OauthClient;
88

9+
use OAuth\Common\Consumer\CredentialsInterface;
910
use OAuth\Common\Http\Uri\UriInterface;
11+
use Magento\Framework\Oauth\Helper\Utility;
1012

1113
/**
1214
* Signature class for Magento REST API.
1315
*/
1416
class Signature extends \OAuth\OAuth1\Signature\Signature
1517
{
18+
/**
19+
* @param Utility $helper
20+
* @param CredentialsInterface $credentials
21+
*/
22+
public function __construct(readonly Utility $helper, CredentialsInterface $credentials)
23+
{
24+
parent::__construct($credentials);
25+
}
26+
1627
/**
1728
* @inheritDoc
1829
*
19-
* In addition to the original method, allows array parameters for filters.
30+
* In addition to the original method, allows array parameters for filters
31+
* and matches validation signature algorithm
2032
*/
2133
public function getSignature(UriInterface $uri, array $params, $method = 'POST')
2234
{
@@ -30,39 +42,17 @@ function ($carry, $item) {
3042
[]
3143
);
3244

33-
$signatureData = [];
34-
foreach (array_merge($queryStringData, $params) as $key => $value) {
35-
$signatureData[rawurlencode($key)] = rawurlencode($value);
36-
}
37-
38-
ksort($signatureData);
39-
40-
// determine base uri
41-
$baseUri = $uri->getScheme() . '://' . $uri->getRawAuthority();
42-
43-
if ('/' == $uri->getPath()) {
44-
$baseUri .= $uri->hasExplicitTrailingHostSlash() ? '/' : '';
45-
} else {
46-
$baseUri .= $uri->getPath();
45+
foreach ($params as $key => $value) {
46+
$queryStringData[rawurlencode($key)] = rawurlencode($value);
4747
}
4848

49-
$baseString = strtoupper($method) . '&';
50-
$baseString .= rawurlencode($baseUri) . '&';
51-
$baseString .= rawurlencode($this->buildSignatureDataString($signatureData));
52-
53-
return base64_encode($this->hash($baseString));
54-
}
55-
56-
/**
57-
* @inheritDoc
58-
*/
59-
protected function hash($data)
60-
{
61-
switch (strtoupper($this->algorithm)) {
62-
case 'HMAC-SHA256':
63-
return hash_hmac('sha256', $data, $this->getSigningKey(), true);
64-
default:
65-
return parent::hash($data);
66-
}
49+
return $this->helper->sign(
50+
$queryStringData,
51+
'SHA256',
52+
$this->credentials->getConsumerSecret(),
53+
$this->tokenSecret,
54+
$method,
55+
(string) $uri
56+
);
6757
}
6858
}

lib/internal/Magento/Framework/Oauth/Helper/Utility.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ public function sign(
4343
$url = null
4444
): string {
4545
unset($params['oauth_signature']);
46-
if (strtoupper($method) === 'GET') {
47-
return parent::sign($params, $params['oauth_signature_method'], $consumerSecret, $tokenSecret, $method, $url);
48-
}
4946

5047
$binaryHash = HMACEncryption::compute(
5148
$this->assembleKey($consumerSecret, $tokenSecret),

0 commit comments

Comments
 (0)