Authentication hooks

This commit is contained in:
FreeScout
2022-06-03 01:49:26 -07:00
parent 1e4e67cc37
commit 04374dccdf
3 changed files with 74 additions and 2 deletions

View File

@@ -104,6 +104,7 @@
"Illuminate\\Validation\\Concerns\\": "overrides/laravel/framework/src/Illuminate/Validation/Concerns/",
"Illuminate\\Mail\\": "overrides/laravel/framework/src/Illuminate/Mail/",
"Illuminate\\Auth\\": "overrides/laravel/framework/src/Illuminate/Auth/",
"Illuminate\\Auth\\Middleware\\": "overrides/laravel/framework/src/Illuminate/Auth/Middleware/",
"Illuminate\\Container\\": "overrides/laravel/framework/src/Illuminate/Container/",
"Lord\\Laroute\\Routes\\": "overrides/lord/laroute/src/Routes/",
"TorMorten\\Eventy\\": "overrides/tormjens/eventy/src/",
@@ -169,6 +170,7 @@
"vendor/laravel/framework/src/Illuminate/Validation/Concerns/ValidatesAttributes.php",
"vendor/laravel/framework/src/Illuminate/Mail/TransportManager.php",
"vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php",
"vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php",
"vendor/laravel/framework/src/Illuminate/Container/Container.php",
"vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php",
"vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php",

View File

@@ -0,0 +1,70 @@
<?php
namespace Illuminate\Auth\Middleware;
use Closure;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Contracts\Auth\Factory as Auth;
class Authenticate
{
/**
* The authentication factory instance.
*
* @var \Illuminate\Contracts\Auth\Factory
*/
protected $auth;
/**
* Create a new middleware instance.
*
* @param \Illuminate\Contracts\Auth\Factory $auth
* @return void
*/
public function __construct(Auth $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string[] ...$guards
* @return mixed
*
* @throws \Illuminate\Auth\AuthenticationException
*/
public function handle($request, Closure $next, ...$guards)
{
\Eventy::action('auth_middleware.handle', $request, $guards, $next);
$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 (empty($guards)) {
return $this->auth->authenticate();
}
foreach ($guards as $guard) {
if ($this->auth->guard($guard)->check()) {
return $this->auth->shouldUse($guard);
}
}
throw new AuthenticationException('Unauthenticated.', $guards);
}
}

View File

@@ -115,7 +115,7 @@ class SessionGuard implements StatefulGuard, SupportsBasicAuth
if ($this->loggedOut) {
return;
}
// If we've already retrieved the user for the current request we can just
// return it back immediately. We do not want to fetch the user data on
// every call to this method because that would be tremendously slow.
@@ -378,7 +378,7 @@ class SessionGuard implements StatefulGuard, SupportsBasicAuth
protected function hasValidCredentials($user, $credentials)
{
// https://github.com/laravel/framework/pull/31357
$validated = ! is_null($user) && $this->provider->validateCredentials($user, $credentials);
$validated = ! is_null($user) && \Eventy::filter('session_guard.validate_credentials', $this->provider->validateCredentials($user, $credentials), $user, $credentials);
if ($validated) {
$this->fireValidatedEvent($user);