0

I'm very new at this and it's my first attempt developing a plugin for Joomla. I'm currently using J5, and I'm trying to develop a custom authentication plugin. At the end of the code I'm using:

$response->status = \Joomla\CMS\Authentication\Authentication::STATUS_SUCCESS;

However, what it does, is refreshing the page and showing me the same login form with empty fields, but no session initiated. I'm kind of lost at this point, maybe somebody can guide me in the next step. This is my code:

defined('_JEXEC') or die;

use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Log\Log;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Factory;
use Joomla\CMS\Authentication\AuthenticationResponse;

class PlgAuthenticationcnflldapauth extends CMSPlugin
{
    public function onUserAuthenticate($credentials, $options, &$response)
    {
        $response = new AuthenticationResponse();

        $username = $credentials['username'];
        $password = $credentials['password'];

    //
    //Authentication code goes here
    //

        $response->status = \Joomla\CMS\Authentication\Authentication::STATUS_SUCCESS;
        $response->error_message = '';
        $response->username = $username;
        $response->email  = '[email protected]';

    return true;
    }
}

I appreciate any help with this. My goal is after this login process, Joomla keeps the user session in the front end. Thank you.

2
  • You should remove $response = new AuthenticationResponse(); from your plugin as it is not required. The $response object is created before the plugin is called and passed to your plugin by reference therefore it does not need to be created again in your plugin. I tested this line by adding it to the default Joomla plugins and it made no difference so I don't believe it is a fix to your issue but it is not necessary either.
    – Irata
    Commented Jun 11 at 10:35
  • $response is not passed by reference. That's why creating a new instance does not work.
    – Sharky
    Commented Jun 12 at 5:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.