-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Session API request (PHP) #13
Comments
Hi @godwin12345 here is a working PHP example on how to generate a signature:
|
|
Same issue , nonce: 1819761929 timestamp: 1570686301 application_id=xx&auth_key=xx&nonce=1819761929×tamp=1570686301 3eae76fd0bb9b469bff758c43ffdd2a665d1b2c2{"application_id": "xxx", "auth_key": "xx", "nonce": "1819761929", "signature": "3eae76fd0bb9b469bff758c43ffdd2a665d1b2c2", "timestamp": "1570686301"}{"errors":["Unexpected signature"]} |
Here is a complete create session request, could you please try it and let us know:
|
Thank you it's fixed |
In a case somebody needs to create a session with user:
|
Warning Example using Be careful when using Try it here: https://onlinephp.io/ <?php
DEFINE('APPLICATION_ID', 1232);
DEFINE('AUTH_KEY', "adasdsad7128334");
DEFINE('AUTH_SECRET', "778adbdasddasd");
DEFINE('USER_LOGIN', "bobson12");
DEFINE('USER_PASSWORD', "qweqwesd");
$nonce = rand();
$timestamp = time();
$signature_string = "application_id=".APPLICATION_ID."&auth_key=".AUTH_KEY."&nonce=".$nonce."×tamp=".$timestamp."&user[login]=".USER_LOGIN."&user[password]=".USER_PASSWORD;
$signature = hash_hmac('sha1', $signature_string , AUTH_SECRET);
$array = array(
'application_id' => APPLICATION_ID,
'auth_key' => AUTH_KEY,
'timestamp' => $timestamp,
'nonce' => $nonce,
'signature' => $signature,
'user[login]' => USER_LOGIN,
'user[password]' => USER_PASSWORD
);
echo http_build_query($array); Expect to see As you can see // copy the above
// replace with
echo urldecode(http_build_query($array)); And now you will get Full code but a bit modern: <?php
require 'vendor/autoload.php'; // Make sure Guzzle is installed and autoloaded
use GuzzleHttp\Client;
// Application credentials
define('APPLICATION_ID', 1232);
define('AUTH_KEY', "adasdsad7128334");
define('AUTH_SECRET', "778adbdasddasd");
// User credentials
define('USER_LOGIN', "bobson12");
define('USER_PASSWORD', "qweqwesd");
// Endpoints
define('CB_API_ENDPOINT', "https://api.connectycube.com");
define('CB_PATH_SESSION', "session.json");
// Generate signature
$nonce = rand();
$timestamp = time();
$signature_string = http_build_query([
'application_id' => APPLICATION_ID,
'auth_key' => AUTH_KEY,
'nonce' => $nonce,
'timestamp' => $timestamp,
'user[login]' => USER_LOGIN,
'user[password]' => USER_PASSWORD
]);
$signature = hash_hmac('sha1', urldecode($signature_string), AUTH_SECRET); // <---- use urldecode
// Build post body
$post_body = [
'application_id' => APPLICATION_ID,
'auth_key' => AUTH_KEY,
'timestamp' => $timestamp,
'nonce' => $nonce,
'signature' => $signature,
'user' => [
'login' => USER_LOGIN,
'password' => USER_PASSWORD
]
];
// Initialize Guzzle client
$client = new Client();
// Make POST request
try {
$response = $client->post(CB_API_ENDPOINT . '/' . CB_PATH_SESSION, [
'json' => $post_body
]);
// Get response body
$body = $response->getBody()->getContents();
// Output response
echo $body;
} catch (\GuzzleHttp\Exception\RequestException $e) {
// If request fails, catch the exception and handle it
echo $e->getMessage();
} |
@eznix86 thanks for letting everyone know, noted! |
Dears,
We are getting this below error while connecting to your api, please check anything missing
Error: {"errors":["Unexpected signature"]}
Php Code:
The text was updated successfully, but these errors were encountered: