Skip to content

Commit 0adf67c

Browse files
committed
Auth: switch to authorization header
1 parent 04ca283 commit 0adf67c

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/HttpClient/Plugin/RequestSignature.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,24 @@ public function __construct($token, $secret)
2727
*/
2828
public function handleRequest(RequestInterface $request, callable $next, callable $first)
2929
{
30-
$params = [];
31-
$headers = [
32-
'PRIVATE-PACKAGIST-API-TOKEN' => $params['key'] = $this->token,
33-
'PRIVATE-PACKAGIST-API-TIMESTAMP' => $params['timestamp'] = $this->getTimestamp(),
34-
'PRIVATE-PACKAGIST-API-NONCE' => $params['cnonce'] = $this->getNonce(),
30+
$params = [
31+
'key' => $this->token,
32+
'timestamp' => $this->getTimestamp(),
33+
'cnonce' => $this->getNonce(),
3534
];
3635

37-
foreach ($headers as $header => $value) {
38-
$request = $request->withHeader($header, $value);
39-
}
40-
4136
$content = $request->getBody()->getContents();
4237
if ($content) {
4338
$params['body'] = $content;
4439
}
4540

46-
$request = $request->withHeader('PRIVATE-PACKAGIST-API-SIGNATURE', $this->generateSignature($request, $params));
41+
$request = $request->withHeader('Authorization', sprintf(
42+
'PACKAGIST-HMAC-SHA256 Key=%s, Timestamp=%s, Cnonce=%s, Signature=%s',
43+
$params['key'],
44+
$params['timestamp'],
45+
$params['cnonce'],
46+
$this->generateSignature($request, $params)
47+
));
4748

4849
return $next($request);
4950
}

0 commit comments

Comments
 (0)