学说authentication
类注册here in the module.config.php
from DoctrineModule
:
'doctrine' => array(
'doctrine_factories' => array(
'cache' => 'DoctrineModule\Service\CacheFactory',
'eventmanager' => 'DoctrineModule\Service\EventManagerFactory',
'driver' => 'DoctrineModule\Service\DriverFactory',
'authenticationadapter' => 'DoctrineModule\Service\Authentication\AdapterFactory',
'authenticationstorage' => 'DoctrineModule\Service\Authentication\StorageFactory',
'authenticationservice' => 'DoctrineModule\Service\Authentication\AuthenticationServiceFactory',
)
)
你可以很容易地覆盖您的自定义工厂这些配置。
我不知道什么是管理这一切,因为我不知道该怎么跟你的社会服务身份验证的样子的最佳方式。您可以覆盖任何这些工厂并添加自定义逻辑,以便从您的社交身份验证服务中注入您的Identity
。
但也许它甚至会更好地不使用教条认证,但将两个认证解决方案合并到一个定制认证服务类中。那取决于你。
我可以给通过改写存储工厂类从您设置$identity
的学说认证存储社会服务的例子。这会给你一个想法如何处理这些事情。
在您的应用程序module.config.php
覆盖与您的自定义工厂类存储工厂的关键(请确保您的模块主义模块加载后使钥匙上配置合并覆盖):
'doctrine' => array(
'doctrine_factories' => array(
'authenticationstorage' => 'Application\Service\Authentication\CustomStorageFactory',
)
)
现在创建这个在您的应用程序文件夹中定制类您CustomStorageFactory
例如可以是这样的:
<?php
namespace Application\Service\Authentication;
use DoctrineModule\Authentication\Storage\ObjectRepository;
use Zend\ServiceManager\ServiceLocatorInterface;
use DoctrineModule\Service\Authentication\StorageFactory;
/**
* Customized factory to inject identity from social authentication
*/
class CustomStorageFactory extends StorageFactory
{
/**
* @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
* @return \Zend\Authentication\AuthenticationService
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
// Construct storage like normally by calling parent class
$doctrineStorage = parent::__construct($serviceLocator);
// Write the identity into the storage
$socialService = $serviceLocator->get('SocialAuthenticationService');
if($socialService->hasIdentity()){
$identity = $socialService->getIdentity();
$doctrineStorage->write($identity);
}
// return the storage
return $doctrineStorage;
}
}
现在你可以做这样的事情:
$serviceLocator= $this->getServiceLocator();
$authService = $serviceLocator->get(`Zend\Authentication\AuthenticationService`);
// Check if we have identity, if not we authenticate
if(!$authService->hasIdentity()){
$authService->authenticate();
)
$authService->getIdentity();
也许不涉及您的问题。但[使用'md5'进行密码加密并不好](http://security.stackexchange.com/a/52463/57364)。 – Wilt
@Wilt“md5”只是暂时的,会让它更安全! –
您正在使用的适配器类是什么? – Wilt