How to extend an authentication plugin

How to extend an authentication plugin

by Albert R. -
Number of replies: 4

I need to extend the external database authentication plugin, because I need to override the user_login() function to add some additional logic (everything else about that plugin works perfectly for my needs).

I've been looking around in the documentation and forums but I can't find any information about how to accomplish this. If someone could point me in the right direction that would be great!

My assumption is that I need to create a new plugin that extends the auth_plugin_db class, and then write there the new user_login() function (95% of the current code will be the same), but I'm not sure what files I need to include in this new plugin, or what libraries I'm supposed to call, and how...

Thanks in advance!

Average of ratings: -
In reply to Albert R.

Re: How to extend an authentication plugin

by Vitaly Potenko -
Picture of Core developers Picture of Plugin developers
Basically you'll want to read this - https://docs.moodle.org/dev/Tutorial and then more specific things about the auth plugin type here - https://docs.moodle.org/dev/Authentication_plugins. That's the basic info about developing plugins for Moodle.
It would also be useful to investigate the existing core auth plugins in Moodle which are located in the '/auth' path of your Moodle installation. You'll surely get some inspiration from the existing auth plugins when developing your own and things will get clearer to you.
In reply to Vitaly Potenko

Re: How to extend an authentication plugin

by Albert R. -
Hi Vitaly, thank you for your reply. It looks like from what you say that I have to develop a stand alone plugin instead of just extending an existing one? My understanding was that I could just "extend" an existing plugin, just overriding the functionalities I need, instead of creating a new plugin, is that not possible?
In reply to Albert R.

Re: How to extend an authentication plugin

by Vitaly Potenko -
Picture of Core developers Picture of Plugin developers

Basically, there is no such thing in Moodle as "extending a plugin". You'll have to create a separate plugin which is based on the existing one. That's what was actually meant when you're told that "you should extend the existing db auth plugin". But don't worry, it's pretty easy if you have some experience in PHP. And that's the recommended way of extending Moodle's functionality.

In reply to Vitaly Potenko

Re: How to extend an authentication plugin

by Albert R. -
I see, I do have experience with PHP, not with Moodle plugins development, but I always like a good challenge! Thanks for your help!