It seems the authentication expired in a very short period, very short

I installed identity plugin.

  1. custom a servicefactory
class AuthenticationServiceFactory implements FactoryInterface
{

    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
    {
        $dbAdapter = $container->get(AdapterInterface::class);

        $authAdapter = new CredentialTreatmentAdapter(
            $dbAdapter,
            'user',
            'username',
            'passwd',
            'SHA1(CONCAT(?, salt)) AND valid=1',
        );

        return new AuthenticationService(null, $authAdapter);
    }
}
  1. config as following in the module.config.php
    'service_manager' => [
        'factories' => [
            AuthenticationService::class => AuthenticationServiceFactory::class, //it works after I added this line !!!!
            AuthenticationServiceInterface::class => AuthenticationServiceFactory::class, //
            AuthManager::class => AuthManagerFactory::class, //use in bootstrap
            Redis::class => CommonRedisFactory::class, //
        ],
    ],
  1. as well I config something in the global.php
    'session_containers' => [
        Laminas\Session\Container::class,
    ],
    'session_storage' => [
        'type' => Laminas\Session\Storage\SessionArrayStorage::class,
    ],
    'session_config' => [
        'cache_expire' => 60 * 24 * 30,
        'cookie_httponly' => true,
        'cookie_lifetime' => 86400 * 30,
        'gc_maxlifetime' => 86400 * 30,
        'name' => 'hcs_erp',
        'remember_me_seconds' => 86400 * 30,
        'use_cookies' => true,
    ],
    'session_manager' => [
        'config' => [
            'class' => Laminas\Session\Config\SessionConfig::class,
            'options' => [
                'name' => 'hcs_erp',
            ],
        ],
        'storage' => Laminas\Session\Storage\SessionArrayStorage::class,
        'validators' => [
            Laminas\Session\Validator\RemoteAddr::class,
            Laminas\Session\Validator\HttpUserAgent::class,
        ],
    ],

When I login with username and password, it works well. However it expired in a very short time, almost 1 hour, then I need to login again, it is very inconvinient.

I don’t know where the problem is.

1 Like

If you are using this in a production environment behind a load balancer, there is a possibility for session to expire based on the session stickiness configuration of the Load Balancer

No load balancer at all, just one single nginx webserver. when server several php project via vitural host

I have the same problem too!