Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit c65de36

Browse files
committed
🚿 OAuth1Provider::getSignature() cleanup
1 parent 63a51cd commit c65de36

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/Core/OAuth1Provider.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,25 +143,31 @@ protected function nonce():string{
143143
* @throws \chillerlan\OAuth\Core\ProviderException
144144
*/
145145
protected function getSignature(string $url, array $params, string $method, string $accessTokenSecret = null):string{
146-
$parseURL = parseUrl($url);
146+
$parsed = parseUrl($url);
147147

148-
if(!isset($parseURL['host']) || !isset($parseURL['scheme']) || !in_array($parseURL['scheme'], ['http', 'https'], true)){
148+
if(!isset($parsed['host']) || !isset($parsed['scheme']) || !in_array($parsed['scheme'], ['http', 'https'], true)){
149149
throw new ProviderException('getSignature: invalid url');
150150
}
151151

152-
$query = $this->parseQuery($parseURL['query'] ?? '');
152+
$query = $this->parseQuery($parsed['query'] ?? '');
153153
$signatureParams = array_merge($query, $params);
154154

155155
unset($signatureParams['oauth_signature']);
156156

157-
$key = implode('&', array_map('rawurlencode', [$this->options->secret, $accessTokenSecret ?? '']));
157+
// https://tools.ietf.org/html/rfc5849#section-3.4.1.1
158158
$data = array_map('rawurlencode', [
159159
strtoupper($method ?? 'POST'),
160-
$parseURL['scheme'].'://'.$parseURL['host'].($parseURL['path'] ?? ''),
160+
$parsed['scheme'].'://'.$parsed['host'].($parsed['path'] ?? ''),
161161
$this->buildQuery($signatureParams),
162162
]);
163163

164-
return base64_encode(hash_hmac('sha1', implode('&', $data), $key, true));
164+
// https://tools.ietf.org/html/rfc5849#section-3.4.2
165+
$key = array_map('rawurlencode', [
166+
$this->options->secret,
167+
$accessTokenSecret ?? ''
168+
]);
169+
170+
return base64_encode(hash_hmac('sha1', implode('&', $data), implode('&', $key), true));
165171
}
166172

167173
/**

0 commit comments

Comments
 (0)