1. 创建一个自定义的ServiceProvider,修改默认的user.auth的service的class,改成自定义的
namespace Drupal\mymodule;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase;
use Symfony\Component\DependencyInjection\Reference;
/**
* Class MyModuleServiceProvider.
*
* @package Drupal\mymodule
*/class MyModuleServiceProvider extends ServiceProviderBase {
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container) {
$definition = $container->getDefinition('user.auth');
$definition->setClass('Drupal\mymodule\UserAuth');
$definition->setArguments(
[
new Reference('entity.manager'),
new Reference('password'),
new Reference('language_manager'),
new Reference('logger.factory'),
new Reference('mymodule.netforum_client'),
]
);
}}
2. 再在这个类里面写自定义认证过程(这个类也可以集成默认的UserAuth)
class FdUserAuth extends UserAuth
{
public function authenticate($username, $password) {
if($username == xx) {...}
}
}