auth = $auth; } /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle($request, Closure $next) { if ($this->auth->guest()) { if ($apiToken = $request->header('X-Cachet-Token')) { try { $this->auth->onceUsingId(User::findByApiToken($apiToken)->id); } catch (ModelNotFoundException $e) { throw new HttpException(401); } } elseif ($request->getUser()) { if ($this->auth->onceBasic() !== null) { throw new HttpException(401); } } else { throw new HttpException(401); } } return $next($request); } }