2019-05-20 07:37:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
|
|
|
|
|
|
|
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];
|
2022-11-22 15:15:52 +01:00
|
|
|
} else {
|
|
|
|
// We replace routes guard by the reverse proxy guard if necessary
|
2022-03-24 14:58:30 +01:00
|
|
|
$proxyGuard = 'reverse-proxy-guard';
|
2022-03-19 00:14:20 +01:00
|
|
|
|
2022-05-19 15:50:06 +02:00
|
|
|
if (config('auth.defaults.guard') === $proxyGuard) {
|
|
|
|
$guards = [$proxyGuard];
|
2022-03-24 14:58:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($guards as $guard) {
|
|
|
|
if ($this->auth->guard($guard)->check()) {
|
2022-09-07 17:54:27 +02:00
|
|
|
$this->auth->shouldUse($guard);
|
2022-11-22 15:15:52 +01:00
|
|
|
|
2022-09-07 17:54:27 +02:00
|
|
|
return;
|
2022-03-24 14:58:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->unauthenticated($request, $guards);
|
|
|
|
}
|
2022-11-22 15:15:52 +01:00
|
|
|
}
|