Hi, I would like to implement multiple authentication methods for EspoCRM Portal login — for example:
To achieve this, I created a custom authentication class DualLoginAuth and set it in data/config.php like this:
'portalAuthenticationProvider' => '\\Espo\\Custom\\Authentication\\DualLoginAuth',
File path:custom/Espo/Custom/Authentication/DualLoginAuth.php
namespace Espo\Custom\Authentication;
use Espo\Core\Authentication\AuthenticationInterface;
use Espo\Core\Authentication\Exception\AuthenticationE xception;
use Espo\ORM\EntityManager;
use Espo\Core\Utils\PasswordHasher;
use Espo\Core\Utils\Log;
class DualLoginAuth implements AuthenticationInterface
{
public function __construct(
protected EntityManager $entityManager,
protected PasswordHasher $passwordHasher,
protected Log $log
) {}
public function authenticate(array $credentials)
{
$this->log->info('[DualLoginAuth] Called'); // for debugging
$userName = $credentials['userName'] ?? null;
$password = $credentials['password'] ?? null;
if ($password === 'oidc-secret') {
$user = $this->entityManager->getRepository('PortalUser')->where(['userName' => $userName])->findOne();
if ($user) return $user;
throw new AuthenticationException('OIDC login failed.');
}
// fallback to normal login
$user = $this->entityManager->getRepository('PortalUser')->where(['userName' => $userName])->findOne();
if (!$user || !$this->passwordHasher->verify($password, $user->get('password'))) {
throw new AuthenticationException('Invalid credentials.');
}
return $user;
}
}
I also did:
But my authenticate() method is never called when logging into the portal UI. No logs are triggered. It seems the custom provider is not even being used.
Is portalAuthenticationProvider still supported in v9.1.5?
Or is there a different method to support multiple login methods for portal users?
Thanks for your help!
- Normal username + password login
- External OIDC token-based login (e.g., use a predefined password like oidc-secret to simulate token login)
To achieve this, I created a custom authentication class DualLoginAuth and set it in data/config.php like this:
'portalAuthenticationProvider' => '\\Espo\\Custom\\Authentication\\DualLoginAuth',
File path:custom/Espo/Custom/Authentication/DualLoginAuth.php
namespace Espo\Custom\Authentication;
use Espo\Core\Authentication\AuthenticationInterface;
use Espo\Core\Authentication\Exception\AuthenticationE xception;
use Espo\ORM\EntityManager;
use Espo\Core\Utils\PasswordHasher;
use Espo\Core\Utils\Log;
class DualLoginAuth implements AuthenticationInterface
{
public function __construct(
protected EntityManager $entityManager,
protected PasswordHasher $passwordHasher,
protected Log $log
) {}
public function authenticate(array $credentials)
{
$this->log->info('[DualLoginAuth] Called'); // for debugging
$userName = $credentials['userName'] ?? null;
$password = $credentials['password'] ?? null;
if ($password === 'oidc-secret') {
$user = $this->entityManager->getRepository('PortalUser')->where(['userName' => $userName])->findOne();
if ($user) return $user;
throw new AuthenticationException('OIDC login failed.');
}
// fallback to normal login
$user = $this->entityManager->getRepository('PortalUser')->where(['userName' => $userName])->findOne();
if (!$user || !$this->passwordHasher->verify($password, $user->get('password'))) {
throw new AuthenticationException('Invalid credentials.');
}
return $user;
}
}
I also did:
- Cleared cache and rebuilt EspoCRM
- Enabled logging ($this->log->info(...))
- Verified the class loads properly
- Made sure portal user exists
But my authenticate() method is never called when logging into the portal UI. No logs are triggered. It seems the custom provider is not even being used.
Is portalAuthenticationProvider still supported in v9.1.5?
Or is there a different method to support multiple login methods for portal users?
Thanks for your help!
Comment