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