1
votes

I have a custom implementation of AuthenticationService that I would like to use in ZfcUser Module but I am able to set this class into the module. The implementation seems to be fixed.

vendor\zf-commons\zfc-user\Module.php

'zfcuser_auth_service' => function ($sm) {
    return new \Zend\Authentication\AuthenticationService(
         $sm->get('ZfcUser\Authentication\Storage\Db'),
         $sm->get('ZfcUser\Authentication\Adapter\AdapterChain')
      );
 }

The original requirement is to keep a unique active session per user that is implemented in my CustomAuthenticationService. Any ideas to solve this problem?

2
What are you trying to accomplish?Shawn
I want to make sure that a user would have just one active session.user2819732
Do you need a custom service for that? Can you please explain in detail what is not working...Wilt
I am using ZfcUser to control my authentication, each request this AuthenticationService verify if I have identity or not then I override this behavior in my custom AuthenticationService and now I can't see how to inject my custom auth service into the ZfcUser without change the vendor code.user2819732
Hey how did you get on with this? Did you find a working solution? I have the same issue heredelboy1978uk

2 Answers

1
votes

Your use case is unclear; normally the authentication adapter is the class that you would normally customise, rather than the actual authentication service.

Nevertheless, you can override the default service with your own providing you register the service with the same name and the module is loaded after the ZfcUser module.

Say your custom authentication service is in your own Auth namespace/module, with the class Auth\Service\CustomAuthenticationService.

Register the service in Auth\Module.php (or depending on the type of factory the module.config.php of that module).

class Module
{
    public function getServiceConfig()
    {
        return [
            'aliases' => [
                'MyAuthenticationService' => 'zfcuser_auth_service',
            ],
            'factories' => [
                'zfcuser_auth_service' => function($sm) {
                    return new \Auth\Service\CustomAuthenticationService(
                        $sm->get('ZfcUser\Authentication\Storage\Db'),
                        $sm->get('ZfcUser\Authentication\Adapter\AdapterChain')
                    );
                },
            ],
        ];
    }
}

Lastly, ensure the module is loaded after ZfcUser in application.config.php.

return [
    'modules' => [
        //...
        'ZfcUser',
        'Auth',
        // ...
    ],
];
0
votes

The auth adapter is just trigged when the login action is performed. To handle each request you can override the storage adapter that allow validate the identify in every request. In your configuration file add a 'ZfcUser\Authentication\Storage\Db' attribute poiting to your custom storage class.

'service_manager' => array(
    'invokables' => array(
    'ZfcUser\Authentication\Storage\Db' => 'MyCustom\Authentication\Storage'),
...