2016-01-10 03:23:35 +08:00
|
|
|
<?php
|
|
|
|
|
2020-02-01 19:42:22 +08:00
|
|
|
namespace BookStack\Auth\Access;
|
2016-01-10 03:23:35 +08:00
|
|
|
|
|
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
|
|
|
use Illuminate\Contracts\Auth\UserProvider;
|
2021-11-20 22:03:56 +08:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2016-01-10 03:23:35 +08:00
|
|
|
|
2020-02-01 19:42:22 +08:00
|
|
|
class ExternalBaseUserProvider implements UserProvider
|
2016-01-10 03:23:35 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The user model.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $model;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* LdapUserProvider constructor.
|
|
|
|
*/
|
2020-02-01 19:42:22 +08:00
|
|
|
public function __construct(string $model)
|
2016-01-10 03:23:35 +08:00
|
|
|
{
|
|
|
|
$this->model = $model;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance of the model.
|
|
|
|
*
|
2021-11-20 22:03:56 +08:00
|
|
|
* @return Model
|
2016-01-10 03:23:35 +08:00
|
|
|
*/
|
|
|
|
public function createModel()
|
|
|
|
{
|
2016-01-12 06:41:05 +08:00
|
|
|
$class = '\\' . ltrim($this->model, '\\');
|
2021-06-26 23:23:15 +08:00
|
|
|
|
|
|
|
return new $class();
|
2016-01-10 03:23:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a user by their unique identifier.
|
|
|
|
*
|
2021-06-26 23:23:15 +08:00
|
|
|
* @param mixed $identifier
|
|
|
|
*
|
2021-11-20 22:03:56 +08:00
|
|
|
* @return Authenticatable|null
|
2016-01-10 03:23:35 +08:00
|
|
|
*/
|
|
|
|
public function retrieveById($identifier)
|
|
|
|
{
|
|
|
|
return $this->createModel()->newQuery()->find($identifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a user by their unique identifier and "remember me" token.
|
|
|
|
*
|
2021-06-26 23:23:15 +08:00
|
|
|
* @param mixed $identifier
|
|
|
|
* @param string $token
|
|
|
|
*
|
2021-11-20 22:03:56 +08:00
|
|
|
* @return Authenticatable|null
|
2016-01-10 03:23:35 +08:00
|
|
|
*/
|
|
|
|
public function retrieveByToken($identifier, $token)
|
|
|
|
{
|
2020-02-01 19:42:22 +08:00
|
|
|
return null;
|
2016-01-10 03:23:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the "remember me" token for the given user in storage.
|
|
|
|
*
|
2021-11-20 22:03:56 +08:00
|
|
|
* @param Authenticatable $user
|
2021-11-23 06:22:31 +08:00
|
|
|
* @param string $token
|
2021-06-26 23:23:15 +08:00
|
|
|
*
|
2016-01-10 03:23:35 +08:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function updateRememberToken(Authenticatable $user, $token)
|
|
|
|
{
|
2020-02-01 19:42:22 +08:00
|
|
|
//
|
2016-01-10 03:23:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a user by the given credentials.
|
|
|
|
*
|
2021-06-26 23:23:15 +08:00
|
|
|
* @param array $credentials
|
|
|
|
*
|
2021-11-20 22:03:56 +08:00
|
|
|
* @return Authenticatable|null
|
2016-01-10 03:23:35 +08:00
|
|
|
*/
|
|
|
|
public function retrieveByCredentials(array $credentials)
|
|
|
|
{
|
|
|
|
// Search current user base by looking up a uid
|
2016-01-12 06:41:05 +08:00
|
|
|
$model = $this->createModel();
|
2021-06-26 23:23:15 +08:00
|
|
|
|
2020-02-01 19:42:22 +08:00
|
|
|
return $model->newQuery()
|
|
|
|
->where('external_auth_id', $credentials['external_auth_id'])
|
2016-01-12 06:41:05 +08:00
|
|
|
->first();
|
2016-01-10 03:23:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate a user against the given credentials.
|
|
|
|
*
|
2021-11-20 22:03:56 +08:00
|
|
|
* @param Authenticatable $user
|
2021-11-23 06:22:31 +08:00
|
|
|
* @param array $credentials
|
2021-06-26 23:23:15 +08:00
|
|
|
*
|
2016-01-10 03:23:35 +08:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function validateCredentials(Authenticatable $user, array $credentials)
|
|
|
|
{
|
2020-02-01 19:42:22 +08:00
|
|
|
// Should be done in the guard.
|
|
|
|
return false;
|
2016-01-10 03:23:35 +08:00
|
|
|
}
|
|
|
|
}
|