Skip to content

Instantly share code, notes, and snippets.

@jblyberg
Forked from frzsombor/gist:ddd0e11f93885060ef35
Last active February 17, 2017 11:54
Show Gist options
  • Save jblyberg/0368a3467a604668c746 to your computer and use it in GitHub Desktop.
Save jblyberg/0368a3467a604668c746 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());
@mvdpoel
Copy link

mvdpoel commented Feb 24, 2016

Anyway pulling their hair out why they're still stuck with laravel 4 too?

https://gist.github.com/mvdpoel/d76f5e90cb9dfd708c9f

@bacanu
Copy link

bacanu commented Feb 17, 2017

If you're trying to figure out where you should actually put this code:
In MOXIEMENAGER_ROOT_FOLDER/plugins/LaravelAuthenticator/Plugin.php

Don't forget to change the config value $moxieManagerConfig['authenticator'] = 'LaravelAuthenticator'; in MOXIEMENAGER_ROOT_FOLDER/config.php

This creates the new authenticator that you can use, see: http://www.moxiemanager.com/documentation/index.php/How_to_make_your_own_Authenticator

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