BookStack/app/Access/ExternalBaseUserProvider.php

84 lines
2.0 KiB
PHP
Raw Normal View History

<?php
2023-05-17 17:56:55 +01:00
namespace BookStack\Access;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Database\Eloquent\Model;
class ExternalBaseUserProvider implements UserProvider
{
public function __construct(
protected string $model
) {
}
/**
* Create a new instance of the model.
*/
public function createModel(): Model
{
$class = '\\' . ltrim($this->model, '\\');
2021-06-26 15:23:15 +00:00
return new $class();
}
/**
* Retrieve a user by their unique identifier.
*/
public function retrieveById(mixed $identifier): ?Authenticatable
{
return $this->createModel()->newQuery()->find($identifier);
}
/**
* Retrieve a user by their unique identifier and "remember me" token.
*
2021-06-26 15:23:15 +00:00
* @param string $token
*/
public function retrieveByToken(mixed $identifier, $token): null
{
return null;
}
/**
* Update the "remember me" token for the given user in storage.
*
* @param Authenticatable $user
* @param string $token
2021-06-26 15:23:15 +00:00
*
* @return void
*/
public function updateRememberToken(Authenticatable $user, $token)
{
//
}
/**
* Retrieve a user by the given credentials.
*/
public function retrieveByCredentials(array $credentials): ?Authenticatable
{
// Search current user base by looking up a uid
$model = $this->createModel();
2021-06-26 15:23:15 +00:00
return $model->newQuery()
->where('external_auth_id', $credentials['external_auth_id'])
->first();
}
/**
* Validate a user against the given credentials.
*/
public function validateCredentials(Authenticatable $user, array $credentials): bool
{
// Should be done in the guard.
return false;
}
public function rehashPasswordIfRequired(Authenticatable $user, #[\SensitiveParameter] array $credentials, bool $force = false)
{
// No action to perform, any passwords are external in the auth system
}
}