-
-
Save bacanu/f9b170a0833cb6b63415599e32b60607 to your computer and use it in GitHub Desktop.
Share Laravel 5.1 session and check authentication from Moxiemanager.
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
<?php | |
/* | |
|-------------------------------------------------------------------------- | |
| Sharing Laravel's session and checking authentication | |
|-------------------------------------------------------------------------- | |
| | |
| Customized Moxiemanager plugin for use in our Laravel App. We use a custom | |
| External authentication module, but you get the gist (ha ha) of it. | |
| Put the Plugin.php file in moxiemanager/plugins/LaravelAuthenticator | |
| and set the following in moxiemanager's config.php: | |
| | |
| $moxieManagerConfig['authenticator'] = 'LaravelAuthenticator'; | |
| | |
| The following code is tested with Laravel 5.1 | |
| | |
| Last update: 2015-11-05 | |
| | |
*/ | |
require '../../../../bootstrap/autoload.php'; | |
$app = require_once '../../../../bootstrap/app.php'; | |
$app->make('Illuminate\Contracts\Http\Kernel') | |
->handle(Illuminate\Http\Request::capture()); | |
class MOXMAN_LaravelAuthenticator_Plugin implements MOXMAN_Auth_IAuthenticator { | |
public function authenticate(MOXMAN_Auth_User $user) { | |
$config = MOXMAN::getConfig(); | |
if (Auth::check()) { | |
$laravel_user = Auth::user(); | |
if ($laravel_user->patron_code == 'STAFF') { | |
$config->replaceVariable("user", $laravel_user->id); | |
return true; | |
} else { | |
return false; | |
} | |
} else { | |
return false; | |
} | |
// Catch all, default to false. | |
return false; | |
} | |
} | |
MOXMAN::getAuthManager()->add("LaravelAuthenticator", new MOXMAN_LaravelAuthenticator_Plugin()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should check out https://gist.github.com/jblyberg/0368a3467a604668c746 for the original gist.