How to attach a password encoder to a User Interface in Silex?

最后都变了- 提交于 2019-12-05 08:37:34

You need to reconstruct the EncoderFactory to add your custom implementation:

<?php

$app = new Silex\Application();
$app['myapp.encoder.base64'] = new Base64PasswordEncoder();
$app['security.encoder_factory'] = $app->share(function ($app) {
    return new EncoderFactory(
        array(
            'Symfony\Component\Security\Core\User\UserInterface' => $app['security.encoder.digest'],
            'MyApp\Model\UserInterface'                          => $app['myapp.encoder.base64'],
        )
    );
});

(oh and please, don't use a Base64Encoder() for password ;))

Ghost8472

I was able to use the accepted answer to fix my problem, but I couldn't assign it to security.encoder_factory directly, so I'm just sharing what I found to work.

instead of:

$app['security.encoder_factory'] = $app->share(function($app) {
    //..see above...//
});

I had to use:

$app->register(new Silex\Provider\SecurityServiceProvider(),array(
    'security.encoder_factory' => $app->share(function($app) {
    //... same as above ...//
    })
));

I'm too new to Silex to know why it didn't work as above for me. My initial guess would be a version difference (question was asked over two years ago). I can assign to security.provider.default before the call to register the module, but I can't seem to assign to security.encoder_factory . I also seem to have to put security.firewalls in the register call.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!