Skip to content

Commit 3b20788

Browse files
committed
AC-14075::Replace carlos-mg89/oauth with PHP Native Functions
1 parent 90ee25b commit 3b20788

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22
/**
3-
* Helper class for generating OAuth related credentials
4-
*
5-
* Copyright © Magento, Inc. All rights reserved.
6-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
75
*/
86
namespace Magento\TestFramework\Authentication;
97

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

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function buildAuthorizationHeaderToRequestToken(
137137
string $signatureMethod = \Magento\Framework\Oauth\Oauth::SIGNATURE_SHA256,
138138
string $httpMethod = 'POST'
139139
): string {
140-
$params['oauth_signature'] = $this->_httpUtility->sign(
140+
$params['oauth_signature'] = $this->getSignature(
141141
$params,
142142
$signatureMethod,
143143
$consumerSecret,
@@ -241,7 +241,7 @@ public function buildAuthorizationHeaderForAPIRequest(
241241
$params = array_merge($params, ['oauth_token' => $token['oauth_token']]);
242242
$params = array_merge($params, $bodyParams);
243243

244-
$params['oauth_signature'] = $this->_httpUtility->sign(
244+
$params['oauth_signature'] = $this->getSignature(
245245
$params,
246246
$signatureMethod,
247247
$consumerSecret,
@@ -253,6 +253,46 @@ public function buildAuthorizationHeaderForAPIRequest(
253253
return $this->_httpUtility->toAuthorizationHeader($params);
254254
}
255255

256+
/**
257+
* Get the signature
258+
*
259+
* @param array $params
260+
* @param string $signatureMethod
261+
* @param string $consumerSecret
262+
* @param string|null $tokenSecret
263+
* @param string $httpMethod
264+
* @param string $requestUrl
265+
* @return string
266+
*/
267+
public function getSignature(
268+
array $params,
269+
string $signatureMethod,
270+
string $consumerSecret,
271+
?string $tokenSecret,
272+
string $httpMethod,
273+
string $requestUrl
274+
): string {
275+
$data = parse_url($requestUrl);
276+
$queryStringData = !isset($data['query']) ? [] : array_reduce(
277+
explode('&', $data['query']),
278+
function ($carry, $item) {
279+
list($key, $value) = explode('=', $item, 2);
280+
$carry[rawurldecode($key)] = rawurldecode($value);
281+
return $carry;
282+
},
283+
[]
284+
);
285+
286+
return $this->_httpUtility->sign(
287+
array_merge($queryStringData, $params),
288+
$signatureMethod,
289+
$consumerSecret,
290+
$tokenSecret,
291+
$httpMethod,
292+
$requestUrl
293+
);
294+
}
295+
256296
/**
257297
* Request token endpoint.
258298
*
@@ -313,10 +353,10 @@ public function fetchResponse(string $url, array $requestBody, array $headers, s
313353
/**
314354
* Builds the bearer token authorization header
315355
*
316-
* @param string $token
356+
* @param string|null $token
317357
* @return array
318358
*/
319-
public function buildBearerTokenAuthorizationHeader(string $token): array
359+
public function buildBearerTokenAuthorizationHeader(?string $token): array
320360
{
321361
return [
322362
'Authorization: Bearer ' . $token

0 commit comments

Comments
 (0)