Skip to content

Instantly share code, notes, and snippets.

@RodolfoSilva
Created June 5, 2014 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RodolfoSilva/1f438da56cb55c1eaea0 to your computer and use it in GitHub Desktop.
Save RodolfoSilva/1f438da56cb55c1eaea0 to your computer and use it in GitHub Desktop.
HOOKS Validação de token
<?php
$token_list = array('_4as82-6assda79sasg_da7s39sa3f32ar6rta' => true,'s796as7dafsdf67d60s9s_df7das67d-796f' => false);
$app->hook(
'slim.before.router',
function () use ($app, $token_list) {
$req = $app->request();
$current_path = $req->getPathInfo();
if (!empty($current_path) && $current_path != '/') {
$access_token = $req->get('access_token');
if (!isset($token_list[$access_token]) || $token_list[$access_token] !== true) {
$app->render(
'default.php',
array('message' => 'O token de acesso fornecido é invalido'),
400
);
$app->stop();
}
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment