Files
nl-admin-api/app/Http/Middleware/Authenticate.php

53 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Middleware;
2014-08-11 10:13:20 -05:00
2014-10-06 15:25:53 -05:00
use Closure;
2015-12-03 12:25:38 -06:00
use Illuminate\Support\Facades\Auth;
use Illuminate\Auth\AuthenticationException;
2014-08-11 10:13:20 -05:00
2015-02-22 20:47:03 -06:00
class Authenticate
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string ...$guards
2015-02-22 20:47:03 -06:00
* @return mixed
*
* @throws \Illuminate\Auth\AuthenticationException
2015-02-22 20:47:03 -06:00
*/
public function handle($request, Closure $next, ...$guards)
2015-02-22 20:47:03 -06:00
{
$this->authenticate($guards);
return $next($request);
}
/**
* Determine if the user is logged in to any of the given guards.
*
* @param array $guards
* @return void
*
* @throws \Illuminate\Auth\AuthenticationException
*/
protected function authenticate(array $guards)
{
if (count($guards) <= 1) {
Auth::guard(array_first($guards))->authenticate();
return Auth::shouldUse($guard);
}
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return Auth::shouldUse($guard);
2015-02-22 20:47:03 -06:00
}
}
2014-08-11 10:13:20 -05:00
throw new AuthenticationException;
2015-02-22 20:47:03 -06:00
}
}