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

**URL:** <https://discourse.laminas.dev/t/it-seems-the-authentication-expired-in-a-very-short-period-very-short/2488>\
**Category:** Components & MVC\
**Tags:** laminas-mvc-plugin-identi\
**Created:** [September 4, 2021, 10:37am UTC](https://discourse.laminas.dev/t/it-seems-the-authentication-expired-in-a-very-short-period-very-short/2488 "2021-09-04T10:37:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jobsfan](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/jobsfan/32/399_2.png) [@jobsfan](https://discourse.laminas.dev/u/jobsfan)\
**Post date:** [September 4, 2021, 10:37am UTC](https://discourse.laminas.dev/t/it-seems-the-authentication-expired-in-a-very-short-period-very-short/2488/1 "2021-09-04T10:37:22Z")

</div>

I installed identity plugin.

1. custom a servicefactory

```auto
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

```auto
    '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

```auto
    '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.

---

<div class="post-metadata">

**Author:** ![Vinith\_Mathews](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/vinith_mathews/32/988_2.png) [@Vinith\_Mathews](https://discourse.laminas.dev/u/Vinith_Mathews)\
**Post date:** [September 5, 2021, 2:33am UTC](https://discourse.laminas.dev/t/it-seems-the-authentication-expired-in-a-very-short-period-very-short/2488/2 "2021-09-05T02:33:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jobsfan](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/jobsfan/32/399_2.png) [@jobsfan](https://discourse.laminas.dev/u/jobsfan)\
**Post date:** [September 5, 2021, 4:01am UTC](https://discourse.laminas.dev/t/it-seems-the-authentication-expired-in-a-very-short-period-very-short/2488/3 "2021-09-05T04:01:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ebuddy](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ebuddy/32/1536_2.png) [@ebuddy](https://discourse.laminas.dev/u/ebuddy)\
**Post date:** [September 5, 2021, 8:18am UTC](https://discourse.laminas.dev/t/it-seems-the-authentication-expired-in-a-very-short-period-very-short/2488/4 "2021-09-05T08:18:24Z")

</div>

I have the same problem too!
