I'm trying to create a script to login in Joomla 4 programmatically and without the users' password.

The users' authentication is done via an external site and if successful the user will be redirected on my Joomla site and will be logged in (without using his Joomla password).

Therefore I'm using this:

use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Event\Dispatcher as EventDispatcher;

$db = JFactory::getDbo();

$q = "SELECT * FROM `#__users` WHERE id = ".$userid;
$user = $db->setQuery($q)->loadAssoc();
$dispatcher = new EventDispatcher();

// Initiate log in
$options = array('action' => 'core.login.site', 'remember' => false);
$results = $dispatcher->triggerEvent('onUserLogin', array($user, $options));

Sadly it doesn't work. I don't get any errors but there is no login.

What is the actual event to execute a users' login?


Your Answer

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

Browse other questions tagged or ask your own question.