This commit is contained in:
freek 2018-11-26 23:04:20 +01:00
parent 3dfaa6901c
commit 94fbcf6264
1 changed files with 16 additions and 14 deletions

View File

@ -60,21 +60,23 @@ abstract class EchoController implements HttpServerInterface
function onError(ConnectionInterface $connection, Exception $exception) function onError(ConnectionInterface $connection, Exception $exception)
{ {
if ($exception instanceof HttpException) { if (! $exception instanceof HttpException) {
$response = new Response($exception->getStatusCode(), [ return;
'Content-Type' => 'application/json'
], json_encode([
'error' => $exception->getMessage()
]));
$connection->send(Psr\str($response));
$connection->close();
} }
$response = new Response($exception->getStatusCode(), [
'Content-Type' => 'application/json'
], json_encode([
'error' => $exception->getMessage()
]));
$connection->send(Psr\str($response));
$connection->close();
} }
public function ensureValidAppId(string $appId) public function ensureValidAppId(string $appId)
{ {
if (! $client = Client::findByAppId($appId)) { if (!$client = Client::findByAppId($appId)) {
throw new HttpException(401, "Unknown app id `{$appId}` provided."); throw new HttpException(401, "Unknown app id `{$appId}` provided.");
} }
@ -86,10 +88,10 @@ abstract class EchoController implements HttpServerInterface
$bodyMd5 = md5($request->getContent()); $bodyMd5 = md5($request->getContent());
$signature = $signature =
"{$request->getMethod()}\n/{$request->path()}\n". "{$request->getMethod()}\n/{$request->path()}\n" .
"auth_key={$request->get('auth_key')}". "auth_key={$request->get('auth_key')}" .
"&auth_timestamp={$request->get('auth_timestamp')}". "&auth_timestamp={$request->get('auth_timestamp')}" .
"&auth_version={$request->get('auth_version')}". "&auth_version={$request->get('auth_version')}" .
"&body_md5={$bodyMd5}"; "&body_md5={$bodyMd5}";
$authSignature = hash_hmac('sha256', $signature, Client::findByAppId($request->get('appId'))->appSecret); $authSignature = hash_hmac('sha256', $signature, Client::findByAppId($request->get('appId'))->appSecret);