Skip to content

Instantly share code, notes, and snippets.

@willianmano
Created September 24, 2015 14:15
Show Gist options
  • Save willianmano/cf92eecdbcded7f818df to your computer and use it in GitHub Desktop.
Save willianmano/cf92eecdbcded7f818df to your computer and use it in GitHub Desktop.
$app->before(function(Request $request, Application $app) {
$pathInfo = $request->getPathInfo();
$openRoutes = [
'/v1/auth/login',
];
if(in_array($pathInfo, $openRoutes)) {
return true;
}
$token = $request->headers->get('Authorization');
$guardian = $app['guardian'];
$validToken = $guardian->validateToken($token);
if (!$validToken) {
return new JsonResponse('Acesso negado', HttpCodes::UNAUTHORIZED);
}
$app['ClientToken'] = strval($validToken);
});
$app->after(function(Request $request, Response $response, Application $app) {
if(isset($app['ClientToken'])) {
$response->headers->set('ClientToken', $app['ClientToken']);
}
// $response->headers->set('Access-Control-Allow-Origin', '*');
$response->headers->set('Access-Control-Allow-Origin', 'http://localhost:8080');
$response->headers->set('Access-Control-Allow-Origin', 'http://localhost:8100');
$response->headers->set('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment