Skip to content

Commit 4e4d672

Browse files
Release 0.8.0
1 parent e72f61f commit 4e4d672

File tree

3 files changed

+31
-37
lines changed

3 files changed

+31
-37
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
# CHANGELOG
22

3+
## 0.8.0 - 2025-06-01
4+
5+
* Adjusted some method modifiers and added return types
6+
* Fixed signature generation with duplicate query parameters
7+
38
## 0.7.0 - 2025-06-01
49

510
* Dropped support for HHVM and PHP <7.2.5
11+
* Dropped support for Guzzle 6.x and PSR-7 1.x
612
* Added support for PHP 8.1, 8.2, 8.3, 8.4
13+
* Add param types to various methods
714

815
## 0.6.0 - 2021-07-13
916

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This project can be installed using Composer. Add the following to your
1313
```json
1414
{
1515
"require": {
16-
"guzzlehttp/oauth-subscriber": "^0.7"
16+
"guzzlehttp/oauth-subscriber": "^0.8"
1717
}
1818
}
1919
```

src/Oauth1.php

+23-36
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ public function __construct(array $config)
7979
* Called when the middleware is handled.
8080
*
8181
* @return \Closure
82+
*
83+
* @throws \InvalidArgumentException
84+
* @throws \RuntimeException
8285
*/
8386
public function __invoke(callable $handler)
8487
{
@@ -91,9 +94,13 @@ public function __invoke(callable $handler)
9194
};
9295
}
9396

94-
private function onBefore(RequestInterface $request)
97+
/**
98+
* @throws \InvalidArgumentException
99+
* @throws \RuntimeException
100+
*/
101+
private function onBefore(RequestInterface $request): RequestInterface
95102
{
96-
$oauthparams = $this->getOauthParams(
103+
$oauthparams = self::getOauthParams(
97104
$this->generateNonce($request),
98105
$this->config
99106
);
@@ -127,11 +134,9 @@ private function onBefore(RequestInterface $request)
127134
* @param RequestInterface $request Request to generate a signature for
128135
* @param array $params Oauth parameters.
129136
*
130-
* @return string
131-
*
132137
* @throws \RuntimeException
133138
*/
134-
public function getSignature(RequestInterface $request, array $params)
139+
public function getSignature(RequestInterface $request, array $params): string
135140
{
136141
// Remove oauth_signature if present
137142
// Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.")
@@ -149,7 +154,7 @@ public function getSignature(RequestInterface $request, array $params)
149154

150155
$baseString = $this->createBaseString(
151156
$request,
152-
$this->prepareParameters($params)
157+
self::prepareParameters($params)
153158
);
154159

155160
// Implements double-dispatch to sign requests
@@ -181,10 +186,8 @@ public function getSignature(RequestInterface $request, array $params)
181186
* timestamp to use separate nonce's.
182187
*
183188
* @param RequestInterface $request Request to generate a nonce for
184-
*
185-
* @return string
186189
*/
187-
public function generateNonce(RequestInterface $request)
190+
private static function generateNonce(RequestInterface $request): string
188191
{
189192
return sha1(uniqid('', true).$request->getUri()->getHost().$request->getUri()->getPath());
190193
}
@@ -199,29 +202,20 @@ public function generateNonce(RequestInterface $request)
199202
* @param RequestInterface $request Request being signed
200203
* @param array $params Associative array of OAuth parameters
201204
*
202-
* @return string Returns the base string
203-
*
204205
* @see https://oauth.net/core/1.0/#sig_base_example
205206
*/
206-
protected function createBaseString(RequestInterface $request, array $params)
207+
protected function createBaseString(RequestInterface $request, array $params): string
207208
{
208209
// Remove query params from URL. Ref: Spec: 9.1.2.
209-
$url = $request->getUri()->withQuery('');
210-
$query = http_build_query($params, '', '&', PHP_QUERY_RFC3986);
211-
212210
return strtoupper($request->getMethod())
213-
.'&'.rawurlencode((string) $url)
214-
.'&'.rawurlencode($query);
211+
.'&'.rawurlencode((string) $request->getUri()->withQuery(''))
212+
.'&'.rawurlencode(Query::build($params));
215213
}
216214

217215
/**
218-
* Convert booleans to strings, removed unset parameters, and sorts the array
219-
*
220-
* @param array $data Data array
221-
*
222-
* @return array
216+
* @param array $data The data array
223217
*/
224-
private function prepareParameters(array $data)
218+
private static function prepareParameters(array $data): array
225219
{
226220
// Parameters are sorted by name, using lexicographical byte value
227221
// ordering. Ref: Spec: 9.1.1 (1).
@@ -238,10 +232,8 @@ private function prepareParameters(array $data)
238232

239233
/**
240234
* @param string $algo Name of selected hashing algorithm (i.e. "md5", "sha256", "haval160,4", etc..)
241-
*
242-
* @return string
243235
*/
244-
private function signUsingHmac(string $algo, string $baseString)
236+
private function signUsingHmac(string $algo, string $baseString): string
245237
{
246238
$key = rawurlencode($this->config['consumer_secret']).'&';
247239
if (isset($this->config['token_secret'])) {
@@ -252,13 +244,12 @@ private function signUsingHmac(string $algo, string $baseString)
252244
}
253245

254246
/**
255-
* @return string
247+
* @throws RuntimeException
256248
*/
257-
private function signUsingRsaSha1(string $baseString)
249+
private function signUsingRsaSha1(string $baseString): string
258250
{
259251
if (!function_exists('openssl_pkey_get_private')) {
260-
throw new \RuntimeException('RSA-SHA1 signature method '
261-
.'requires the OpenSSL extension.');
252+
throw new \RuntimeException('RSA-SHA1 signature method requires the OpenSSL extension.');
262253
}
263254

264255
$privateKey = openssl_pkey_get_private(
@@ -285,10 +276,8 @@ private function signUsingPlaintext(string $baseString)
285276
* Builds the Authorization header for a request
286277
*
287278
* @param array $params Associative array of authorization parameters.
288-
*
289-
* @return array
290279
*/
291-
private function buildAuthorizationHeader(array $params)
280+
private function buildAuthorizationHeader(array $params): array
292281
{
293282
foreach ($params as $key => $value) {
294283
$params[$key] = $key.'="'.rawurlencode((string) $value).'"';
@@ -309,10 +298,8 @@ private function buildAuthorizationHeader(array $params)
309298
*
310299
* @param string $nonce Unique nonce
311300
* @param array $config Configuration options of the plugin.
312-
*
313-
* @return array
314301
*/
315-
private function getOauthParams(string $nonce, array $config)
302+
private static function getOauthParams(string $nonce, array $config): array
316303
{
317304
$params = [
318305
'oauth_consumer_key' => $config['consumer_key'],

0 commit comments

Comments
 (0)