James Cole
2023-01-01 14:25:52 +01:00
parent c60120ac20
commit c3ce9e896e
5 changed files with 56 additions and 37 deletions

View File

@@ -30,6 +30,7 @@ use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\Request;
use Log;
/**
@@ -50,26 +51,37 @@ class RemoteUserGuard implements Guard
// @phpstan-ignore-next-line
public function __construct(UserProvider $provider, Application $app) // @phpstan-ignore-line
{
/** @var Request $request */
$request = $app->get('request');
Log::debug(sprintf('Created RemoteUserGuard for "%s"', $request?->getRequestUri()));
$this->application = $app;
$this->provider = $provider;
$this->user = null;
}
/**
* @return bool
*/
public function viaRemember(): bool {
Log::debug(sprintf('Now at %s', __METHOD__));
return false;
}
/**
*
*/
public function authenticate(): void
{
Log::debug(sprintf('Now at %s', __METHOD__));
if (!is_null($this->user)) {
Log::debug('User is found.');
if (null !== $this->user) {
Log::debug(sprintf('%s is found: #%d, "%s".', get_class($this->user), $this->user->id, $this->user->email));
return;
}
// Get the user identifier from $_SERVER or apache filtered headers
$header = config('auth.guard_header', 'REMOTE_USER');
$userID = request()->server($header) ?? apache_request_headers()[$header] ?? null;
$userID = 'james@firefly';
if (null === $userID) {
Log::error(sprintf('No user in header "%s".', $header));
throw new FireflyException('The guard header was unexpectedly empty. See the logs.');
@@ -103,6 +115,8 @@ class RemoteUserGuard implements Guard
*/
public function guest(): bool
{
Log::debug(sprintf('Now at %s', __METHOD__));
$this->authenticate();
return !$this->check();
}
@@ -111,6 +125,8 @@ class RemoteUserGuard implements Guard
*/
public function check(): bool
{
Log::debug(sprintf('Now at %s', __METHOD__));
$this->authenticate();
return !is_null($this->user());
}
@@ -119,6 +135,8 @@ class RemoteUserGuard implements Guard
*/
public function user(): ?User
{
Log::debug(sprintf('Now at %s', __METHOD__));
$this->authenticate();
return $this->user;
}
@@ -127,6 +145,7 @@ class RemoteUserGuard implements Guard
*/
public function hasUser()
{
Log::debug(sprintf('Now at %s', __METHOD__));
// TODO: Implement hasUser() method.
}
@@ -135,6 +154,7 @@ class RemoteUserGuard implements Guard
*/
public function id(): ?User
{
Log::debug(sprintf('Now at %s', __METHOD__));
return $this->user;
}
@@ -143,6 +163,7 @@ class RemoteUserGuard implements Guard
*/
public function setUser(Authenticatable $user)
{
Log::debug(sprintf('Now at %s', __METHOD__));
$this->user = $user;
}
@@ -151,6 +172,7 @@ class RemoteUserGuard implements Guard
*/
public function validate(array $credentials = [])
{
Log::debug(sprintf('Now at %s', __METHOD__));
throw new FireflyException('Did not implement RemoteUserGuard::validate()');
}
}