function signUrl($myUrlToSign, $privateKey) { // parse the url $url = parse_url($myUrlToSign); $urlPartToSign = $url['path'] . "?" . $url['query']; // Decode the private key into its binary format $decodedKey = decodeBase64UrlSafe($privateKey); // Create a signature using the private key and the URL-encoded // string using HMAC SHA1. This signature will be binary. $signature = hash_hmac("sha1", $urlPartToSign, $decodedKey, true); $encodedSignature = encodeBase64UrlSafe($signature); return $myUrlToSign . "&signature=" . $encodedSignature; }
function signURLForGoogle($urlToSign) { $clientID = Kurogo::getOptionalSiteVar('GOOGLE_MAPS_CLIENT_ID', false, 'maps'); $privateKey = Kurogo::getOptionalSiteVar('GOOGLE_MAPS_PRIVATE_KEY', false, 'maps'); if ($clientID && $privateKey) { // parse the url $url = parse_url($myUrlToSign); if (strpos($url['query'], 'client=') === false) { $url['query'] .= "client={$clientID}"; } $urlPartToSign = $url['path'] . "?" . $url['query']; // Decode the private key into its binary format $decodedKey = decodeBase64UrlSafe($privateKey); // Create a signature using the private key and the URL-encoded // string using HMAC SHA1. This signature will be binary. $signature = hash_hmac("sha1", $urlPartToSign, $decodedKey, true); $encodedSignature = encodeBase64UrlSafe($signature); return $urlToSign . "&signature=" . $encodedSignature; } return $urlToSign; }