repository = $repository; } /** * Check if a request from the daemon can be properly attributed back to a single node instance. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed * * @throws \Symfony\Component\HttpKernel\Exception\HttpException */ public function handle(Request $request, Closure $next) { if (in_array($request->route()->getName(), $this->except)) { return $next($request); } $token = $request->bearerToken(); if (is_null($token)) { throw new HttpException(401, null, null, ['WWW-Authenticate' => 'Bearer']); } try { $node = $this->repository->findFirstWhere([['daemonSecret', '=', $token]]); } catch (RecordNotFoundException $exception) { throw new AccessDeniedHttpException; } $request->attributes->set('node', $node); return $next($request); } }