diff --git a/flextype/routes/api.php b/flextype/routes/api.php index db19cc96..c83f12a9 100644 --- a/flextype/routes/api.php +++ b/flextype/routes/api.php @@ -12,18 +12,26 @@ namespace Flextype; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; +/** + * Validate auth token + */ +function validate_auth_token($request, $flextype) : bool +{ + return isset($request->getQueryParams()['auth_token']) && $request->getQueryParams()['auth_token'] == $flextype->registry->get('settings.auth_token') ? true : false; +} + $app->get('/api/entries', function (Request $request, Response $response, array $args) use ($flextype) { // Get Query Params $query = $request->getQueryParams(); - // - if (!isset($query['auth_token'])) { - return $response->withJson(["detail" => "Incorrect authentication credentials."]); + // Validate auth token + if (!validate_auth_token($request, $flextype)) { + return $response->withJson(["detail" => "Incorrect authentication credentials."], 404); } // Response data - $data = []; + $data = ['s']; // Return response return $response->withJson($data);