This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

rand0mb1ts
rand0mb1ts

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!

axomat
axomat

Did you make any progress with this? I have the same requirement now?

sulaz1x
sulaz1x

Same for me :-) any progress ?

axomat
axomat

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.

sulaz1x
sulaz1x

Ok cool ! Van you post it on github ? Or send it to me ? Robin.fave@gmail.com thanks :-)

axomat
axomat

Sent to you by email

jr13428199
jr13428199

can you send it to me too (jr1342@gmail.com)? i'm stuck with this too >_< Thanks in advance.

roy.shay8298
roy.shay8298

Hi axomat - would you be willing to send me your implementation as well, please? roy dot shay at gmail dot com. Thanks!

funteapot15611
funteapot15611

@axomat, can you send it to me too(gzakay@163.com)? Thank you very much.>axomat said:

Sent to you by email

funteapot15611
funteapot15611

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.

sqzaman21683
sqzaman21683

@axomat, can you please share your code with me (sqzaman@gmail.com)

prophet111422439
prophet111422439

@axomat, can you please send it to me too, very appreciate ( prophet1114@gmail.com)

sqzaman21683
sqzaman21683

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

kp22989
kp22989

@axomat, can you please share your code with me too kp@c42.at

yksun23476
yksun23476

@axomat, can you please send it to me too, very appreciate (sunyakun00@gmail.com)

khoatrand
khoatrand

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,

khoatrand
khoatrand

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

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.