public function testSignRequest() { $time = 1441955581; $expected = 'a2f5a5d56660a648f1c8f3b5f92c746a014cd02e82b28a9891e8c4d4f7998b32'; $signature = Security::signRequest('client_secret', 'PUT', 'http://localhost/', '{}', $time); $this->assertEquals($expected, $signature); }
/** * @param callable $handler * @param string $clientKey * @param string $clientSecret * @return callable */ public static function signRequest(callable $handler, $clientKey, $clientSecret) { return function (array $request) use($handler, $clientKey, $clientSecret) { $now = time(); // Client and time stamp $request['headers']['HM-Client'] = [$clientKey]; $request['headers']['HM-Timestamp'] = [$now]; // Sign and add $body = isset($request['body']) ? $request['body'] : ''; $signature = Security::signRequest($clientSecret, $request['http_method'], Core::url($request), $body, $now); $request['headers']['HM-Signature'] = [$signature]; // Send the request using the handler and return the response. return $handler($request); }; }