This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I am currently working on a Laravel 4.2 app. I have implemented LDAP authentication with no user data in the database. Would it be possible to use the same LDAP driver with OctoberCMS? I suspect it should work fine if October is using the following interfaces for authentication:
- Illuminate\Auth\UserInterface
- Illuminate\Auth\UserProviderInterface
- Illuminate\Auth\AuthManager
I am looking to move to a CMS for static page maintenance and many of the other features OctoberCMS has. However, I cannot take the time to rewrite the LDAP driver.
Thanks for any insight you can give!
I made this work for me, I extended UserAccount in a small plugin, created a backend settings page for the ldap credentials and it was straightforward in the end. But I have a very simple use case; to authenticate a user against ldap and nothing else.
can you send it to me too (jr1342@gmail.com)? i'm stuck with this too >_< Thanks in advance.
Hi axomat - would you be willing to send me your implementation as well, please? roy dot shay at gmail dot com. Thanks!
@axomat, can you send it to me too(gzakay@163.com)? Thank you very much.>axomat said:
Sent to you by email
axomat said:
I made this work for me, I extended UserAccount in a small plugin, created a backend settings page for the ldap credentials and it was straightforward in the end. But I have a very simple use case; to authenticate a user against ldap and nothing else.
Please send to me: gzakay@163.com, thank you.
@axomat, can you please send it to me too, very appreciate ( prophet1114@gmail.com)
Here is a way to override back-end authentication, i made it work for backend user authentication using rest service
//Put this code in your custom Plugin, then write ure authentication logic inside signin_onSubmit()
class Plugin extends PluginBase
{
public $elevated = true;
public function boot() {
\Backend\Controllers\Auth::extend(function($controller) {
if(\Backend\Classes\BackendController::$action == 'signin') {
try {
if (post('postback')) {
return $this->signin_onSubmit();
}
}
catch (Exception $ex) {
Flash::error($ex->getMessage());
}
}
});
}
public function registerComponents()
{
}
public function registerSettings()
{
}
public function signin_onSubmit()
{
$rules = [
'login' => 'required|between:2,255',
'password' => 'required|between:4,255'
];
$validation = Validator::make(post(), $rules);
if ($validation->fails()) {
throw new ValidationException($validation);
}
// Authenticate user
$user = BackendAuth::authenticate([
'login' => post('login'),
'password' => post('password')
], true);
//dd($user);
// Load version updates
UpdateManager::instance()->update();
// Log the sign in event
AccessLog::add($user);
// Redirect to the intended page after successful sign in
return Backend::redirectIntended('backend');
}
Last updated
Thanks for your contribution, sqzaman21683 I have tried your code. It works but failed in my case. The problem with your example code is: the signin_onSubmit will be called twice.
- First time, it will be called from your anonymous class in your plugin.
- Second time, it will be called in the Auth controller class of backend module. That being said: your approach will face to a big problem as the final call (Auth controller) will win. The mechanism of extending class cannot help to override completely the function signin_onSubmit
So, I would propose another approach and I have tested it successfully. My approach follows below steps:
Step 1: Inject a piece of Javascript code into the backend auth view to replace the action URL by the URL handled by your own controller class in your plugin.
Step 2: Implement your own controller plugin with whatever logic you want. I will send the example code for you guys if you want to have a look for the reference.
Cheers,
I put the whole solution and problems I have faced to implement this POC here. So, you can check it out for reference: [https://www.learn4.fun/octobercms-ldap-plugin/]
1-17 of 17