AuthenticateWithBasicAuth.php 856B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace Illuminate\Auth\Middleware;
  3. use Closure;
  4. use Illuminate\Contracts\Auth\Factory as AuthFactory;
  5. class AuthenticateWithBasicAuth
  6. {
  7. /**
  8. * The guard factory instance.
  9. *
  10. * @var \Illuminate\Contracts\Auth\Factory
  11. */
  12. protected $auth;
  13. /**
  14. * Create a new middleware instance.
  15. *
  16. * @param \Illuminate\Contracts\Auth\Factory $auth
  17. * @return void
  18. */
  19. public function __construct(AuthFactory $auth)
  20. {
  21. $this->auth = $auth;
  22. }
  23. /**
  24. * Handle an incoming request.
  25. *
  26. * @param \Illuminate\Http\Request $request
  27. * @param \Closure $next
  28. * @param string|null $guard
  29. * @return mixed
  30. */
  31. public function handle($request, Closure $next, $guard = null)
  32. {
  33. return $this->auth->guard($guard)->basic() ?: $next($request);
  34. }
  35. }