Silex Custom Auth with Guard

时间:2017-06-15 16:51:27

标签: php security token silex guard

我尝试按照Silex official website上的教程进行操作,但在将Authenticator注册为服务时出现错误。

Catchable fatal error: Argument 1 passed to App\Security\TokenAuthenticator::__construct() must be an instance of App\Security\EncoderFactoryInterface, instance of Symfony\Component\Security\Core\Encoder\EncoderFactory given, called in C:\wamp\www\api\src\app.php on line 41 and defined in C:\wamp\www\api\src\App\Security\TokenAuthenticator.php on line 17

这是我的app.php

$app = new Silex\Application(['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 App\Security\TokenAuthenticator($app['security.encoder_factory']);
};

$app->register(new Silex\Provider\SecurityServiceProvider());

return $app;

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

1 个答案:

答案 0 :(得分:0)

缺少使用声明:

dosage['Diff'] = dosage.iloc[:,0] - dosage.iloc[:,1]