GIF89a;
Direktori : /home/serb/www/api/src/Middleware/ |
Current File : /home/serb/www/api/src/Middleware/Authentication.php |
<?php namespace Mar\Middleware; class Authentication { public static function handle() { $app = \Slim\Slim::getInstance(); $authorization = $app->request->headers->get('Authorization'); if (!$authorization) { $headers = getallheaders(); $authorization = isset($headers['Authorization']) ? $headers['Authorization'] : null; } $arr = explode(' ', $authorization); if (empty($arr) || !is_array($arr) || count($arr) < 2) { return self::error($app); } if ((list($type, $token) = $arr) && $token !== $app->config('token') ) { return self::error($app); } } protected static function error($app) { return $app->halt(403, json_encode([ 'code' => 403, 'message' => [ 'Authorization Required' ] ])); } }