【问题标题】:Silex Custom Auth with Guard带保护的 Silex 自定义身份验证
【发布时间】:2017-06-15 16:51:27
【问题描述】:

我尝试按照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 的参数配置此服务?你能帮帮我吗?

【问题讨论】:

  • 只是一个简单的截图,你可以尝试在你的 TokenAuthenticator.php 文件的开头添加一个use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface 吗?似乎缺少此接口的命名空间

标签: php security token silex symfony-guard


【解决方案1】:

use 语句丢失:

use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-01
    • 2022-12-10
    • 1970-01-01
    • 2010-11-20
    • 2018-06-25
    • 1970-01-01
    • 2018-09-26
    相关资源
    最近更新 更多