]> BookStack Code Mirror - bookstack/blob - app/Auth/Access/ExternalBaseUserProvider.php
Update settings.php
[bookstack] / app / Auth / Access / ExternalBaseUserProvider.php
1 <?php
2
3 namespace BookStack\Auth\Access;
4
5 use Illuminate\Contracts\Auth\Authenticatable;
6 use Illuminate\Contracts\Auth\UserProvider;
7
8 class ExternalBaseUserProvider implements UserProvider
9 {
10
11     /**
12      * The user model.
13      *
14      * @var string
15      */
16     protected $model;
17
18     /**
19      * LdapUserProvider constructor.
20      * @param             $model
21      */
22     public function __construct(string $model)
23     {
24         $this->model = $model;
25     }
26
27     /**
28      * Create a new instance of the model.
29      *
30      * @return \Illuminate\Database\Eloquent\Model
31      */
32     public function createModel()
33     {
34         $class = '\\' . ltrim($this->model, '\\');
35         return new $class;
36     }
37
38     /**
39      * Retrieve a user by their unique identifier.
40      *
41      * @param  mixed $identifier
42      * @return \Illuminate\Contracts\Auth\Authenticatable|null
43      */
44     public function retrieveById($identifier)
45     {
46         return $this->createModel()->newQuery()->find($identifier);
47     }
48
49     /**
50      * Retrieve a user by their unique identifier and "remember me" token.
51      *
52      * @param  mixed  $identifier
53      * @param  string $token
54      * @return \Illuminate\Contracts\Auth\Authenticatable|null
55      */
56     public function retrieveByToken($identifier, $token)
57     {
58         return null;
59     }
60
61
62     /**
63      * Update the "remember me" token for the given user in storage.
64      *
65      * @param  \Illuminate\Contracts\Auth\Authenticatable $user
66      * @param  string                                     $token
67      * @return void
68      */
69     public function updateRememberToken(Authenticatable $user, $token)
70     {
71         //
72     }
73
74     /**
75      * Retrieve a user by the given credentials.
76      *
77      * @param  array $credentials
78      * @return \Illuminate\Contracts\Auth\Authenticatable|null
79      */
80     public function retrieveByCredentials(array $credentials)
81     {
82         // Search current user base by looking up a uid
83         $model = $this->createModel();
84         return $model->newQuery()
85             ->where('external_auth_id', $credentials['external_auth_id'])
86             ->first();
87     }
88
89     /**
90      * Validate a user against the given credentials.
91      *
92      * @param  \Illuminate\Contracts\Auth\Authenticatable $user
93      * @param  array                                      $credentials
94      * @return bool
95      */
96     public function validateCredentials(Authenticatable $user, array $credentials)
97     {
98         // Should be done in the guard.
99         return false;
100     }
101 }