-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* WIP replace sessions with Laravel * #9566 Laravel auth system integration * #9566 fixing session disable const checking and initialization * #9566 laravel session WIP * #9566 session regenration and old session manager clean up * #9566 added remember me functionality * #9566 fixed logout with auth key details persistence * #9566 fixed device force logout redirect issue * #9566 fixed login issue after migration from older session implementation * #9566 completed sign in/out as and updated session data update in PKPRequest::__destruct * #9566 updates based on PR review * #9566 added check to make sure seesion table exists before saving session * #9566 moved session storage update within register_shutdown_function * #9566 removed unused function param * #9566 added upgrade migration * #9566 fixed issue and doc blocks based on PR review * #9566 removed older implementation cookie issue override method as fixed by setting domain * #9566 removed previously added application upgrade settings from migration tool * #9566 trying to fix mysql build issue * #9566 added db service provider re-registration at install time * #9566 added cookie encryption ability * #9566 session disable check moved to PKPSessionGuard with session user_id key update * #9566 fixed typo * #9566 command line session issue * #9566 clean up of old session manager and dao related implementations * #9566 session default base path update * #9566 session default base path revert back * #9566 fixed cookie path issue * #9566 removed AUTH_KEY_* const usage and related code --------- Co-authored-by: Alec Smecher <alec@smecher.bc.ca>
- Loading branch information
1 parent
6b52af7
commit 5b34729
Showing
60 changed files
with
1,404 additions
and
1,181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/core/PKPAuthManager.php | ||
* | ||
* Copyright (c) 2024 Simon Fraser University | ||
* Copyright (c) 2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class PKPAuthManager | ||
* | ||
* @brief Register session guard and appropriate user provider to handle authentication | ||
*/ | ||
|
||
namespace PKP\core; | ||
|
||
use APP\facades\Repo; | ||
use APP\core\Application; | ||
use InvalidArgumentException; | ||
use PKP\core\PKPSessionGuard; | ||
use PKP\core\PKPUserProvider; | ||
|
||
class PKPAuthManager extends \Illuminate\Auth\AuthManager | ||
{ | ||
/** | ||
* @copydoc \Illuminate\Auth\AuthManager::$app | ||
* | ||
* @var \Illuminate\Contracts\Foundation\Application|\PKP\core\PKPContainer | ||
*/ | ||
protected $app; | ||
|
||
/** | ||
* @copydoc \Illuminate\Auth\AuthManager::__construct($app) | ||
*/ | ||
public function __construct($app) | ||
{ | ||
$this->app = $app; | ||
|
||
$this->userResolver = function ($guard = null) { | ||
|
||
if ($userId = Application::get()->getRequest()->getSessionGuard()->getUserId()) { | ||
return Repo::user()->get($userId); | ||
} | ||
|
||
return null; | ||
}; | ||
} | ||
|
||
/** | ||
* @copydoc \Illuminate\Auth\AuthManager::createUserProvider($provider = null) | ||
*/ | ||
public function createUserProvider($provider = null) | ||
{ | ||
if (is_null($config = $this->getProviderConfiguration($provider))) { | ||
return; | ||
} | ||
|
||
if (isset($this->customProviderCreators[$driver = ($config['driver'] ?? null)])) { | ||
return call_user_func( | ||
$this->customProviderCreators[$driver], $this->app, $config | ||
); | ||
} | ||
|
||
return match ($driver) { | ||
'database' => $this->createDatabaseProvider($config), | ||
'eloquent' => $this->createEloquentProvider($config), | ||
PKPUserProvider::AUTH_PROVIDER => $this->createPKPUserProvider($config), | ||
default => throw new InvalidArgumentException( | ||
"Authentication user provider [{$driver}] is not defined." | ||
), | ||
}; | ||
} | ||
|
||
/** | ||
* Create an instance of the PKPUserProvider. | ||
*/ | ||
public function createPKPUserProvider(array $config = []): PKPUserProvider | ||
{ | ||
return app()->get(PKPUserProvider::class); | ||
} | ||
|
||
/** | ||
* @copydoc \Illuminate\Auth\AuthManager::createSessionDriver($name, $config) | ||
* | ||
* @return \PKP\core\PKPSessionGuard | ||
*/ | ||
public function createSessionDriver($name, $config) | ||
{ | ||
$provider = $this->createUserProvider($config['provider'] ?? null); | ||
|
||
$guard = new PKPSessionGuard( | ||
$name, | ||
$provider, | ||
$this->app['session.store'], | ||
); | ||
|
||
// When using the remember me functionality of the authentication services | ||
// we will need to set the encryption instance of the guard, which allows | ||
// secure, encrypted cookie values to get generated for those cookies. | ||
if (method_exists($guard, 'setCookieJar')) { | ||
$guard->setCookieJar($this->app['cookie']); | ||
} | ||
|
||
if (method_exists($guard, 'setDispatcher')) { | ||
$guard->setDispatcher($this->app['events']); | ||
} | ||
|
||
if (method_exists($guard, 'setRequest')) { | ||
$guard->setRequest($this->app->refresh('request', $guard, 'setRequest')); | ||
} | ||
|
||
if (isset($config['remember'])) { | ||
$guard->setRememberDuration($config['remember']); | ||
} | ||
|
||
return $guard; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/core/PKPAuthServiceProvider.php | ||
* | ||
* Copyright (c) 2024 Simon Fraser University | ||
* Copyright (c) 2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class PKPAuthServiceProvider | ||
* | ||
* @brief Register auth driver, manager and related services | ||
*/ | ||
|
||
namespace PKP\core; | ||
|
||
use PKP\core\PKPAuthManager; | ||
use PKP\core\PKPUserProvider; | ||
use Illuminate\Contracts\Auth\Guard; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Database\ConnectionInterface; | ||
use Illuminate\Contracts\Auth\Factory as AuthFactory; | ||
|
||
class PKPAuthServiceProvider extends \Illuminate\Auth\AuthServiceProvider | ||
{ | ||
/** | ||
* Bootstrap any application services. | ||
*/ | ||
public function boot() | ||
{ | ||
Auth::provider( | ||
PKPUserProvider::AUTH_PROVIDER, | ||
fn ($app, array $config) => $app->get(PKPUserProvider::class) | ||
); | ||
} | ||
|
||
/** | ||
* @copydoc \Illuminate\Auth\AuthServiceProvider::register() | ||
*/ | ||
public function register() | ||
{ | ||
parent::register(); | ||
|
||
$this->app->singleton(AuthFactory::class, fn($app) => $app->get('auth')); | ||
|
||
$this->app->singleton( | ||
PKPUserProvider::class, | ||
fn ($app) => new PKPUserProvider( | ||
$app->get(ConnectionInterface::class), | ||
new \Illuminate\Hashing\BcryptHasher(), | ||
'users' | ||
) | ||
); | ||
|
||
$this->app->singleton(Guard::class, fn ($app) => $app->get('auth.driver')); | ||
|
||
$this->app->bind( | ||
\Illuminate\Contracts\Cookie\QueueingFactory::class, | ||
fn ($app) => $app->get('cookie') | ||
); | ||
} | ||
|
||
/** | ||
* @copydoc \Illuminate\Auth\AuthServiceProvider::registerAuthenticator() | ||
*/ | ||
protected function registerAuthenticator() | ||
{ | ||
$this->app->singleton('auth', fn ($app) => new PKPAuthManager($app)); | ||
|
||
$this->app->singleton('auth.driver', fn ($app) => $app['auth']->guard()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.