Created
February 13, 2015 10:41
-
-
Save mchristie/43c5d5680a7da6d3980d to your computer and use it in GitHub Desktop.
GeckoForm URL encoded parameters example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// Build an array of the information you need to include in the request | |
$intended_parameters = [ | |
'per_page' => '15', | |
'page' => '1', | |
'form_id' => '4007', | |
'keyword' => 'search terms', | |
'include' => 'labels:all,assigned,user,contact', | |
]; | |
// Retrieve your token information from a secure storage location | |
$token_information = json_decode(Session::get('token_information')); | |
/* | |
This will have a data structure similar to this | |
$token_information = [ | |
'key' => 'KfdS1T0N2buSUSt0bRd2oGMhmbO6gVhp05oByr32G3VUWEsMcmV7nthIM8cINk6M', | |
'secret' => 'R1rkbq3oavo13PiX6A0sesqeUD6ya6I7OGJmZqXSGcdnMU5OZ7n1De8opTJDmR06', | |
// Using a timestamp is an easy way to ensure the nonce always increments | |
'nonce' => 1423823278321 | |
]; | |
*/ | |
// Increment the nonce to ensure it is higher than the previously used nonce | |
$token_information['nonce'] += 2; | |
// Add the nonce and key to the parameters | |
// Do NOT add the secret to the array which will be sent to the API | |
$intended_parameters['key'] = $intended_parameters['key']; | |
$intended_parameters['nonce'] = $intended_parameters['nonce']; | |
// Select only the values from of this | |
$values = array_values($intended_parameters); | |
// At this point we can add the secret in, this array will not be sent | |
$values[] = $token_information['secret']; | |
// Sort the values by string | |
sort($values, SORT_STRING); | |
// And join them by - | |
$sign_str = implode('-', $values); | |
// Create an sha256 hash of this string which will be our request signature | |
$signature = hash('sha256', $sign_str); | |
// And add this signature into the intended parameters array | |
$intended_parameters['signature'] = $signature; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment