Skip to content

Commit 0ebb372

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

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed

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

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
11
<?php
2-
/************************************************************************
3-
*
2+
/**
43
* Copyright 2024 Adobe
54
* All Rights Reserved.
6-
*
7-
* NOTICE: All information contained herein is, and remains
8-
* the property of Adobe and its suppliers, if any. The intellectual
9-
* and technical concepts contained herein are proprietary to Adobe
10-
* and its suppliers and are protected by all applicable intellectual
11-
* property laws, including trade secret and copyright laws.
12-
* Dissemination of this information or reproduction of this material
13-
* is strictly forbidden unless prior written permission is obtained
14-
* from Adobe.
15-
* ************************************************************************
165
*/
176
declare(strict_types=1);
187

198
namespace Magento\Framework\Oauth\Helper;
209

2110
use Laminas\Crypt\Hmac as HMACEncryption;
22-
use Laminas\OAuth\Http\Utility as HTTPUtility;
2311

24-
class Utility extends HTTPUtility
12+
class Utility
2513
{
2614
/**
2715
* Generate signature string
@@ -35,18 +23,19 @@ class Utility extends HTTPUtility
3523
* @return string
3624
*/
3725
public function sign(
38-
array $params,
39-
$signatureMethod,
40-
$consumerSecret,
41-
$tokenSecret = null,
42-
$method = null,
43-
$url = null
26+
array $params,
27+
string $signatureMethod,
28+
string $consumerSecret,
29+
?string $tokenSecret = null,
30+
?string $method = null,
31+
?string $url = null
4432
): string {
4533
unset($params['oauth_signature']);
4634

35+
$parts = explode('-', $signatureMethod);
4736
$binaryHash = HMACEncryption::compute(
4837
$this->assembleKey($consumerSecret, $tokenSecret),
49-
$signatureMethod,
38+
count($parts) > 1 ? $parts[1] : $signatureMethod,
5039
$this->getBaseSignatureString($params, $method, $url),
5140
HMACEncryption::OUTPUT_BINARY
5241
);
@@ -68,7 +57,7 @@ private function assembleKey(string $consumerSecret, ?string $tokenSecret): stri
6857
$parts[] = $tokenSecret;
6958
}
7059
foreach ($parts as $key => $secret) {
71-
$parts[$key] = self::urlEncode($secret);
60+
$parts[$key] = $this->urlEncode($secret);
7261
}
7362

7463
return implode('&', $parts);
@@ -86,20 +75,20 @@ private function getBaseSignatureString(array $params, $method = null, $url = nu
8675
{
8776
$encodedParams = [];
8877
foreach ($params as $key => $value) {
89-
$encodedParams[self::urlEncode($key)] =
90-
self::urlEncode($value);
78+
$encodedParams[$this->urlEncode($key)] =
79+
$this->urlEncode($value);
9180
}
9281
$baseStrings = [];
9382
if (isset($method)) {
9483
$baseStrings[] = strtoupper($method);
9584
}
9685
if (isset($url)) {
97-
$baseStrings[] = self::urlEncode($url);
86+
$baseStrings[] = $this->urlEncode($url);
9887
}
9988
if (isset($encodedParams['oauth_signature'])) {
10089
unset($encodedParams['oauth_signature']);
10190
}
102-
$baseStrings[] = self::urlEncode(
91+
$baseStrings[] = $this->urlEncode(
10392
$this->toByteValueOrderedQueryString($encodedParams)
10493
);
10594

@@ -128,4 +117,16 @@ private function toByteValueOrderedQueryString(array $params): string
128117
}
129118
return implode('&', $return);
130119
}
120+
121+
/**
122+
* URL encode a value
123+
*
124+
* @param string $value
125+
* @return string
126+
*/
127+
private function urlEncode(string $value): string
128+
{
129+
$encoded = rawurlencode($value);
130+
return str_replace('%7E', '~', $encoded);
131+
}
131132
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function buildAuthorizationHeader(
156156
$headerParameters = array_merge($headerParameters, $params);
157157
$headerParameters['oauth_signature'] = $this->hmacSignatureHelper->sign(
158158
$params,
159-
'SHA256',
159+
$signatureMethod,
160160
$headerParameters['oauth_consumer_secret'],
161161
$headerParameters['oauth_token_secret'],
162162
$httpMethod,
@@ -192,7 +192,7 @@ protected function _validateSignature($params, $consumerSecret, $httpMethod, $re
192192

193193
$calculatedSign = $this->hmacSignatureHelper->sign(
194194
$params,
195-
'SHA256',
195+
$params['oauth_signature_method'],
196196
$consumerSecret,
197197
$tokenSecret,
198198
$httpMethod,

0 commit comments

Comments
 (0)