带防护装置的 Silex 自定义身份验证



我尝试按照Silex官方网站上的教程进行操作,但是当身份验证器注册为服务时出现错误。

Catchable fatal error: Argument 1 passed to AppSecurityTokenAuthenticator::__construct() must be an instance of AppSecurityEncoderFactoryInterface, instance of SymfonyComponentSecurityCoreEncoderEncoderFactory given, called in C:wampwwwapisrcapp.php on line 41 and defined in C:wampwwwapisrcAppSecurityTokenAuthenticator.php on line 17

这是我的应用程序.php

$app = new SilexApplication(['debug' => true]);
$app['security.firewalls'] = array(
    'main' => array(
        'guard' => array(
            'authenticators' => array(
                'app.token_authenticator'
            ),
            // Using more than 1 authenticator, you must specify
            // which one is used as entry point.
            // 'entry_point' => 'app.token_authenticator',
        ),
        // configure where your users come from. Hardcode them, or load them from somewhere
        // http://silex.sensiolabs.org/doc/providers/security.html#defining-a-custom-user-provider
        'users' => array(
        //raw password = foo
            'test' => array('ROLE_USER', '$2y$10$3i9/lVd8UOFIJ6PAMFt8gu3/r5g0qeCJvoSlLCsvMTythye19F77a'),
        ),
        // 'anonymous' => true
    ),
);
$app['app.token_authenticator'] = function ($app) {
    return new AppSecurityTokenAuthenticator($app['security.encoder_factory']);
};
$app->register(new SilexProviderSecurityServiceProvider());
return $app;

TokenAuthenticator与示例相同。如何使用实现AppSecurityEncoderFactoryInterface的参数配置此服务?你能帮我吗?

use 语句缺失:

use SymfonyComponentSecurityCoreEncoderEncoderFactoryInterface;

最新更新