Skip to content

Instantly share code, notes, and snippets.

@bacanu
Forked from jblyberg/Plugin.php
Created February 17, 2017 11:54
Show Gist options
  • Save bacanu/f9b170a0833cb6b63415599e32b60607 to your computer and use it in GitHub Desktop.
Save bacanu/f9b170a0833cb6b63415599e32b60607 to your computer and use it in GitHub Desktop.
Share Laravel 5.1 session and check authentication from Moxiemanager.
<?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());
@bacanu
Copy link
Author

bacanu commented Feb 17, 2017

You should check out https://gist.github.com/jblyberg/0368a3467a604668c746 for the original gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment