forked from psecio/secure-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-client.php
More file actions
35 lines (28 loc) · 771 Bytes
/
test-client.php
File metadata and controls
35 lines (28 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
require_once 'vendor/autoload.php';
$client = new GuzzleHttp\Client();
$hostnaem = 'http://localhost:8080';
$username = 'user1';
$apiKey = '[... key here ...]';
$res = $client->post($hostname.'/user/login', [
'form_params' => [
'username' => $username,
'key' => $apiKey
]
]);
$result = json_decode($res->getBody());
if ($result->success == false) {
die('Oops! '.$result->message);
var_export($result);
}
// Now make a request with the key
$session = $result->message->session;
$body = '';
$messageHash = hash_hmac('SHA512', $body, $session.time());
$res = $client->post($hostname.'/test', [
'headers' => [
'X-Token' => $apiKey,
'X-Token-Hash' => $messageHash
]
]);
var_export((string)$res->getBody());