mirror of
https://github.com/anonaddy/anonaddy
synced 2026-04-25 17:15:29 +02:00
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Facades\Webauthn;
|
|
use Closure;
|
|
use Illuminate\Contracts\Auth\Factory as AuthFactory;
|
|
use Illuminate\Support\Facades\Redirect;
|
|
|
|
class VerifyWebauthn
|
|
{
|
|
/**
|
|
* The auth factory instance.
|
|
*
|
|
* @var \Illuminate\Contracts\Auth\Factory
|
|
*/
|
|
protected $auth;
|
|
|
|
/**
|
|
* Create a Webauthn.
|
|
*
|
|
* @param \Illuminate\Contracts\Config\Repository $config
|
|
* @param \Illuminate\Contracts\Auth\Factory $auth
|
|
*/
|
|
public function __construct(AuthFactory $auth)
|
|
{
|
|
$this->auth = $auth;
|
|
}
|
|
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \Closure $next
|
|
* @param string|null $guard
|
|
* @return mixed
|
|
*/
|
|
public function handle($request, Closure $next, $guard = null)
|
|
{
|
|
if (Webauthn::webauthnEnabled() && ! Webauthn::check()) {
|
|
abort_if($this->auth->guard($guard)->guest(), 401, trans('webauthn::errors.user_unauthenticated'));
|
|
|
|
if (Webauthn::enabled($request->user($guard))) {
|
|
if ($request->hasSession() && $request->session()->has('url.intended')) {
|
|
return Redirect::to(route('webauthn.login'));
|
|
} else {
|
|
return Redirect::guest(route('webauthn.login'));
|
|
}
|
|
}
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|