I have Implemented a login module with Zend_Auth & Doctrine , and its working fine as expected, now that I have implemented Social login too in the module, in this case I need to bypass Password check , as Password are not required in such cases once the user is validated by 3rd party providers(eg Facebook etc).
So I have modified by function in case of social login attempt ,
In controller
$authService = $this->getServiceLocator()->get('Zend\Authentication\AuthenticationService');
$adapter = $authService->getAdapter();
$adapter->setIdentityValue($userProfile->email);
$adapter->setCredentialValue('NA'); // <----- I have used "NA" to notify its an social login
And in module.config.php
'doctrine' => array(
'authentication' => array(
'orm_default' => array(
'object_manager' => 'Doctrine\ORM\EntityManager',
'identity_class' => 'Account\Entity\Account',
'identity_property' => 'username',
'credential_property' => 'password',
'credential_callable' => function(Entity\Account $user, $passwordGiven) {
if($passwordGiven == 'NA')
return true;
else
return md5($passwordGiven) == $user->getHpassword();
},
)
),
its working fine , but I am not sure is it the correct way to do it ? Any suggestion or more feasible way to do it.
The doctrine
authenticationclasses are registered here in themodule.config.phpfromDoctrineModule:You can easily overwrite these configurations with your custom factories.
I am not sure what is the best way to manage all this since I have no clue what your authentication with your social service looks like. You can overwrite any of those factories and add your custom logic to inject your
Identityfrom your social authentication service.But maybe it would even be better to not use doctrine authentication at all but combine both authentication solutions into one custom authentication service class. That is up to you.
I will can give an example for setting the
$identityfrom you social service in the doctrine authentication storage by overwriting the storage factory class. This will give you an idea how to work with these things.In your application
module.config.phpoverwrite the key for the storage factory with your custom factory class (make sure your module is loaded after doctrine module so the key is overwritten on config merging):Now create this custom class in your application folder. Your
CustomStorageFactorycould for example look like this:Now you can do something like this: