$router->before('GET', '/secured/.*', function () use($app) { $requestHeaders = apache_request_headers(); if (!isset($requestHeaders['Authorization'])) { header('HTTP/1.0 401 Unauthorized'); echo "No token provided."; exit; } $authorizationHeader = $requestHeaders['Authorization']; if ($authorizationHeader == null) { header('HTTP/1.0 401 Unauthorized'); echo "No authorization header sent"; exit; } $token = str_replace('Bearer ', '', $authorizationHeader); try { $app->setCurrentToken($token); } catch (\Auth0\SDK\Exception\CoreException $e) { header('HTTP/1.0 401 Unauthorized'); echo "Invalid token"; exit; } }); $router->get('/ping', function () use($app) { echo json_encode($app->publicPing()); }); $router->get('/secured/ping', function () use($app) { echo json_encode($app->privatePing()); }); $router->set404(function () { header('HTTP/1.1 404 Not Found'); echo "Page not found";