* @author Graham Campbell * @author James Brooks */ class Authenticate { /** * The authentication guard instance. * * @var \Illuminate\Contracts\Auth\Guard */ protected $auth; /** * Create a new authenticate middleware instance. * * @param \Illuminate\Contracts\Auth\Guard $auth * * @return void */ public function __construct(Guard $auth) { $this->auth = $auth; } /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle(Request $request, Closure $next) { if ($this->auth->guest()) { throw new HttpException(401); } return $next($request); } }