mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Apply code style * Remove explicit call to register policies * Shift core files * Shift config files * Default config files In an effort to make upgrading the constantly changing config files easier, Shift defaulted them and merged your true customizations - where ENV variables may not be used. * Bump Laravel dependencies * Add type hints for Laravel 10 * Shift cleanup * wip * wip * sync translation * Sync back config * Public Path Binding * QueryException * monolog * db::raw * monolog * db::raw * fix larastan collections * fix phpstan bug looping forever * larastan errors * larastan: fix column type * styleci * initialize array * fixes * fixes --------- Co-authored-by: Shift <shift@laravelshift.com>
46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Models\User;
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use LibreNMS\Authentication\LegacyAuth;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class LegacyExternalAuth
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \Closure $next
|
|
*/
|
|
public function handle(Request $request, Closure $next, $guard = null): Response
|
|
{
|
|
if (! Auth::guard($guard)->check()) {
|
|
// check for get variables
|
|
if ($request->isMethod('get') && $request->has(['username', 'password'])) {
|
|
Auth::attempt($request->only(['username', 'password']));
|
|
}
|
|
|
|
if (LegacyAuth::get()->authIsExternal()) {
|
|
$credentials = [
|
|
'username' => LegacyAuth::get()->getExternalUsername(),
|
|
'password' => isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '',
|
|
];
|
|
|
|
if (! Auth::guard($guard)->attempt($credentials)) {
|
|
$message = ''; // no debug info for now...
|
|
|
|
// force user to failure page
|
|
return response(view('auth.external-auth-failed')->with('message', $message));
|
|
}
|
|
}
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|