]> BookStack Code Mirror - bookstack/blob - app/Access/ExternalBaseUserProvider.php
Opensearch: Fixed XML declaration when php short tags enabled
[bookstack] / app / Access / ExternalBaseUserProvider.php
1 <?php
2
3 namespace BookStack\Access;
4
5 use Illuminate\Contracts\Auth\Authenticatable;
6 use Illuminate\Contracts\Auth\UserProvider;
7 use Illuminate\Database\Eloquent\Model;
8
9 class ExternalBaseUserProvider implements UserProvider
10 {
11     public function __construct(
12         protected string $model
13     ) {
14     }
15
16     /**
17      * Create a new instance of the model.
18      */
19     public function createModel(): Model
20     {
21         $class = '\\' . ltrim($this->model, '\\');
22
23         return new $class();
24     }
25
26     /**
27      * Retrieve a user by their unique identifier.
28      */
29     public function retrieveById(mixed $identifier): ?Authenticatable
30     {
31         return $this->createModel()->newQuery()->find($identifier);
32     }
33
34     /**
35      * Retrieve a user by their unique identifier and "remember me" token.
36      *
37      * @param string $token
38      */
39     public function retrieveByToken(mixed $identifier, $token): null
40     {
41         return null;
42     }
43
44     /**
45      * Update the "remember me" token for the given user in storage.
46      *
47      * @param Authenticatable $user
48      * @param string          $token
49      *
50      * @return void
51      */
52     public function updateRememberToken(Authenticatable $user, $token)
53     {
54         //
55     }
56
57     /**
58      * Retrieve a user by the given credentials.
59      */
60     public function retrieveByCredentials(array $credentials): ?Authenticatable
61     {
62         // Search current user base by looking up a uid
63         $model = $this->createModel();
64
65         return $model->newQuery()
66             ->where('external_auth_id', $credentials['external_auth_id'])
67             ->first();
68     }
69
70     /**
71      * Validate a user against the given credentials.
72      */
73     public function validateCredentials(Authenticatable $user, array $credentials): bool
74     {
75         // Should be done in the guard.
76         return false;
77     }
78
79     public function rehashPasswordIfRequired(Authenticatable $user, #[\SensitiveParameter] array $credentials, bool $force = false)
80     {
81         // No action to perform, any passwords are external in the auth system
82     }
83 }