Authenticate.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Http\Middleware;
  3. use Closure;
  4. use Illuminate\Contracts\Auth\Factory as Auth;
  5. use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
  6. use Tymon\JWTAuth\Exceptions\JWTException;
  7. use Tymon\JWTAuth\Facades\JWTAuth;
  8. use Tymon\JWTAuth\JWT;
  9. use Tymon\JWTAuth\Payload;
  10. class Authenticate
  11. {
  12. /**
  13. * The authentication guard factory instance.
  14. *
  15. * @var \Illuminate\Contracts\Auth\Factory
  16. */
  17. protected $auth;
  18. /**
  19. * Create a new middleware instance.
  20. *
  21. * @param \Illuminate\Contracts\Auth\Factory $auth
  22. * @return void
  23. */
  24. public function __construct(Auth $auth)
  25. {
  26. $this->auth = $auth;
  27. }
  28. /**
  29. * Handle an incoming request.
  30. *
  31. * @param \Illuminate\Http\Request $request
  32. * @param \Closure $next
  33. * @param string|null $guard
  34. * @return mixed
  35. */
  36. public function handle($request, Closure $next, $guard = null)
  37. {
  38. if ($this->auth->guard($guard)->guest()) {
  39. return response('Unauthorized.', 401);
  40. }
  41. return $next($request);
  42. }
  43. }