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;
|
|
|
|
|
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.
|
2016-01-12 06:41:05 +08:00
|
|
|
* @param $model
|
2016-01-10 03:23:35 +08:00
|
|
|
*/
|
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.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Model
|
|
|
|
*/
|
|
|
|
public function createModel()
|
|
|
|
{
|
2016-01-12 06:41:05 +08:00
|
|
|
$class = '\\' . ltrim($this->model, '\\');
|
2016-01-10 03:23:35 +08:00
|
|
|
return new $class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a user by their unique identifier.
|
|
|
|
*
|
|
|
|
* @param mixed $identifier
|
|
|
|
* @return \Illuminate\Contracts\Auth\Authenticatable|null
|
|
|
|
*/
|
|
|
|
public function retrieveById($identifier)
|
|
|
|
{
|
|
|
|
return $this->createModel()->newQuery()->find($identifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a user by their unique identifier and "remember me" token.
|
|
|
|
*
|
|
|
|
* @param mixed $identifier
|
2016-01-12 06:41:05 +08:00
|
|
|
* @param string $token
|
2016-01-10 03:23:35 +08:00
|
|
|
* @return \Illuminate\Contracts\Auth\Authenticatable|null
|
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Contracts\Auth\Authenticatable $user
|
|
|
|
* @param string $token
|
|
|
|
* @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.
|
|
|
|
*
|
|
|
|
* @param array $credentials
|
|
|
|
* @return \Illuminate\Contracts\Auth\Authenticatable|null
|
|
|
|
*/
|
|
|
|
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();
|
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.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Contracts\Auth\Authenticatable $user
|
|
|
|
* @param array $credentials
|
|
|
|
* @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
|
|
|
}
|
|
|
|
}
|