public function handle($request, Closure $next) { // Проверяем есть ли ключ oauth $redis = \App::make('redis'); if ($redis->exists('docs_token')) { return $next($request); } try { // Если ключа нет, пробуем его получить $client = new \GuzzleHttp\Client(); $response = $client->post(\Config::get('docs-api.server') . 'api/oauth/access_token', ['body' => ['client_secret' => \Config::get('docs-api.secret'), 'client_id' => 'hotdocs']]); $json = $response->json(); if (isset($json['access_token']) && isset($json['expires_in'])) { // Сохраняем ключ и успешно завершаем фильтр $redis->set('docs_token', $json['access_token']); $redis->expire('docs_token', $json['expires_in'] - 1); return $next($request); } else { throw new \Exception("Response error"); } } catch (\Exception $e) { // Если что-то не так выбрасываем на страницу ошибки abort(503); } }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $ga = \App::make('\\App\\Services\\GoogleLogin'); if (!$ga->isLoggedIn()) { return redirect('login'); } return $next($request); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $instance = \App::make('MyService'); if ($instance->check_if_user_agent_is_forbidden()) { \App::abort(403, 'Access denied'); } else { return $next($request); } }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $numArgs = func_num_args(); $types = array(); for ($i = 2; $i < $numArgs; $i++) { array_push($types, func_get_arg($i)); } $userSys = \App::make('UserSys'); $search = array_search($userSys->type, $types); if (!is_int($search)) { throw new RestException(__FILE__, "Sin autorización.", 403, ['message' => 'Sin autorización.']); } return $next($request); }
public function handle($request, Closure $next) { // Получаем строку из запроса и если пользователь уже не залогинен продолжаем $auth_string = \Input::get('a'); if (!$auth_string || $this->auth->check()) { return $next($request); } $authString = \App::make('AuthString'); $authString->set($auth_string); // делаем попытку входа через строку if ($authString->isValid()) { $this->auth->attempt(['auth_string' => $auth_string]); } return $next($request); }
public function handle($request, Closure $next) { // Проверяем наличие ключей у пользователя $crmUser = \App::make('CRMUser'); try { $keys = $crmUser->getRegs(true); } catch (\Exception $e) { // Если произошел сбой получения ключей throw new NoKeysException(); } // если нет, отправляем на страницу *нет ключей* или 401 ошибку (обработчик App\Exceptions\Handler.php) if (empty($keys)) { throw new NoKeysException(); } return $next($request); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $token = $request->header('Authorization'); if (!isset($token)) { throw new RestException(__FILE__, "Falta token de autorización.", 401, ['message' => 'Falta token de autorización.']); } $user = Auth\UserFromToken::getUser($token); if (!$user) { throw new RestException(__FILE__, "Token no válido.", 401, ["message" => "Token no válido."]); } $tokenRefresh = Auth\AuthUser::verify($user); if (!$tokenRefresh) { throw new RestException(__FILE__, "Token obsoleto.", 401, ["message" => "Token obsoleto."]); } $userSys = \App::make('UserSys'); $userSys->load($user); $userSys->token = $tokenRefresh; return $next($request); }
/** * Create a new filter instance. * * @param Guard $auth * @return void */ public function __construct() { $this->auth = \App::make('SSOBroker'); }