Skip to content

Commit

Permalink
calculate sig a little bit differently
Browse files Browse the repository at this point in the history
  • Loading branch information
chregu committed Oct 26, 2020
1 parent bf010da commit ba43df3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"require": {
"php": "~7.0",
"ext-json": "*",
"guzzlehttp/psr7": "^1.7"
}
}
16 changes: 7 additions & 9 deletions src/SignUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public static function signUrl($url, $signKey, $until = null, $roundDateUpTo = 3
/**
* Signs a rokka URL with a sign key and optional signature options.
*
* @since 1.12.0
*
* @param string|UriInterface $url
* @param string $signKey
* @param array|null $options
Expand All @@ -66,29 +64,29 @@ public static function signUrlWithOptions($url, $signKey, $options = null)
}
}

$signature = self::getSignature($url, $sigOptsBase64, $signKey);
if (null !== $sigOptsBase64) {
// append sigopts to return url
// append sigopts to url
$url = Uri::withQueryValue($url, 'sigopts', urlencode($sigOptsBase64));
} else {
// else remove, if exists
$url = Uri::withoutQueryValue($url, 'sigopts');
}
$signature = self::getSignature($url, $signKey);
return Uri::withQueryValue($url, 'sig', $signature);
}

/**
* Gets signature for an Uri
*
* @param \Psr\Http\Message\UriInterface $url
* @param string|null $optionsBase64
* @param string $signKey
*
* @return string
*/
public static function getSignature(UriInterface $url, string $optionsBase64 = null, string $signKey): string
public static function getSignature(UriInterface $url, string $signKey): string
{
// remove sig and sigopts, if they exist
// remove sig if it exists
$url = Uri::withoutQueryValue($url, 'sig');
$url = Uri::withoutQueryValue($url, 'sigopts');

$query = $url->getQuery();
$urlPath = $url->getPath() . ($query ? '?'.$query : '');
Expand All @@ -97,7 +95,7 @@ public static function getSignature(UriInterface $url, string $optionsBase64 = n
$urlPath = '/'.$urlPath;
}

$sigString = $urlPath . ':' . ($optionsBase64 ?? '') . ':' . $signKey;
$sigString = $urlPath . ':' . $signKey;
return self::calculateSignature($sigString);
}

Expand Down

0 comments on commit ba43df3

Please sign in to comment.