1
1
<?php
2
- /************************************************************************
3
- *
2
+ /**
4
3
* Copyright 2024 Adobe
5
4
* 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
- * ************************************************************************
16
5
*/
17
6
declare (strict_types=1 );
18
7
19
8
namespace Magento \Framework \Oauth \Helper ;
20
9
21
10
use Laminas \Crypt \Hmac as HMACEncryption ;
22
- use Laminas \OAuth \Http \Utility as HTTPUtility ;
23
11
24
- class Utility extends HTTPUtility
12
+ class Utility
25
13
{
26
14
/**
27
15
* Generate signature string
@@ -35,18 +23,19 @@ class Utility extends HTTPUtility
35
23
* @return string
36
24
*/
37
25
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
44
32
): string {
45
33
unset($ params ['oauth_signature ' ]);
46
34
35
+ $ parts = explode ('- ' , $ signatureMethod );
47
36
$ binaryHash = HMACEncryption::compute (
48
37
$ this ->assembleKey ($ consumerSecret , $ tokenSecret ),
49
- $ signatureMethod ,
38
+ count ( $ parts ) > 1 ? $ parts [ 1 ] : $ signatureMethod ,
50
39
$ this ->getBaseSignatureString ($ params , $ method , $ url ),
51
40
HMACEncryption::OUTPUT_BINARY
52
41
);
@@ -68,7 +57,7 @@ private function assembleKey(string $consumerSecret, ?string $tokenSecret): stri
68
57
$ parts [] = $ tokenSecret ;
69
58
}
70
59
foreach ($ parts as $ key => $ secret ) {
71
- $ parts [$ key ] = self :: urlEncode ($ secret );
60
+ $ parts [$ key ] = $ this -> urlEncode ($ secret );
72
61
}
73
62
74
63
return implode ('& ' , $ parts );
@@ -86,20 +75,20 @@ private function getBaseSignatureString(array $params, $method = null, $url = nu
86
75
{
87
76
$ encodedParams = [];
88
77
foreach ($ params as $ key => $ value ) {
89
- $ encodedParams [self :: urlEncode ($ key )] =
90
- self :: urlEncode ($ value );
78
+ $ encodedParams [$ this -> urlEncode ($ key )] =
79
+ $ this -> urlEncode ($ value );
91
80
}
92
81
$ baseStrings = [];
93
82
if (isset ($ method )) {
94
83
$ baseStrings [] = strtoupper ($ method );
95
84
}
96
85
if (isset ($ url )) {
97
- $ baseStrings [] = self :: urlEncode ($ url );
86
+ $ baseStrings [] = $ this -> urlEncode ($ url );
98
87
}
99
88
if (isset ($ encodedParams ['oauth_signature ' ])) {
100
89
unset($ encodedParams ['oauth_signature ' ]);
101
90
}
102
- $ baseStrings [] = self :: urlEncode (
91
+ $ baseStrings [] = $ this -> urlEncode (
103
92
$ this ->toByteValueOrderedQueryString ($ encodedParams )
104
93
);
105
94
@@ -128,4 +117,16 @@ private function toByteValueOrderedQueryString(array $params): string
128
117
}
129
118
return implode ('& ' , $ return );
130
119
}
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
+ }
131
132
}
0 commit comments