3 namespace BookStack\Access;
5 use Illuminate\Contracts\Auth\Authenticatable;
6 use Illuminate\Contracts\Auth\UserProvider;
7 use Illuminate\Database\Eloquent\Model;
9 class ExternalBaseUserProvider implements UserProvider
11 public function __construct(
12 protected string $model
17 * Create a new instance of the model.
19 public function createModel(): Model
21 $class = '\\' . ltrim($this->model, '\\');
27 * Retrieve a user by their unique identifier.
29 public function retrieveById(mixed $identifier): ?Authenticatable
31 return $this->createModel()->newQuery()->find($identifier);
35 * Retrieve a user by their unique identifier and "remember me" token.
37 * @param string $token
39 public function retrieveByToken(mixed $identifier, $token): null
45 * Update the "remember me" token for the given user in storage.
47 * @param Authenticatable $user
48 * @param string $token
52 public function updateRememberToken(Authenticatable $user, $token)
58 * Retrieve a user by the given credentials.
60 public function retrieveByCredentials(array $credentials): ?Authenticatable
62 // Search current user base by looking up a uid
63 $model = $this->createModel();
65 return $model->newQuery()
66 ->where('external_auth_id', $credentials['external_auth_id'])
71 * Validate a user against the given credentials.
73 public function validateCredentials(Authenticatable $user, array $credentials): bool
75 // Should be done in the guard.
79 public function rehashPasswordIfRequired(Authenticatable $user, #[\SensitiveParameter] array $credentials, bool $force = false)
81 // No action to perform, any passwords are external in the auth system