2019-05-20 07:37:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
2022-03-24 14:58:30 +01:00
|
|
|
use Illuminate\Support\Arr;
|
2019-05-20 07:37:41 +02:00
|
|
|
|
|
|
|
class Authenticate extends Middleware
|
|
|
|
{
|
2022-03-24 14:58:30 +01:00
|
|
|
/**
|
|
|
|
* Determine if the user is logged in to any of the given guards.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param array $guards
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @throws \Illuminate\Auth\AuthenticationException
|
|
|
|
*/
|
|
|
|
protected function authenticate($request, array $guards)
|
|
|
|
{
|
|
|
|
if (empty($guards)) {
|
|
|
|
// Will retreive the default guard
|
|
|
|
$guards = [null];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We inject the reserve-proxy guard to ensure it will be available for every routes
|
|
|
|
// besides their declared guards. This way we ensure priority to declared guards and
|
|
|
|
// a fallback to the reverse-proxy guard
|
|
|
|
$proxyGuard = 'reverse-proxy-guard';
|
2022-03-19 00:14:20 +01:00
|
|
|
|
2022-03-24 14:58:30 +01:00
|
|
|
if (config('auth.defaults.guard') === $proxyGuard && !Arr::has($guards, $proxyGuard)) {
|
|
|
|
$guards[] = $proxyGuard;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($guards as $guard) {
|
|
|
|
if ($this->auth->guard($guard)->check()) {
|
|
|
|
return $this->auth->shouldUse($guard);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->unauthenticated($request, $guards);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|