2
votes

I have registered a MySQL-based UserProvider with my $app, as described in: http://www.bubblecode.net/en/2012/08/28/mysql-authentication-in-silex-the-php-micro-framework/

I have set my passwords to use sha1 successfully, so far, so good.

$app['security.encoder.digest'] = $app->share(function ($app) {
    // use the sha1 algorithm
    // don't base64 encode the password
    // use only 1 iteration
    return new MessageDigestPasswordEncoder('sha1', false, 1);
});

My problem is: users are authenticated or rejected as appropriate, with redirect to the default route in case of successful authentication, but the login is not preserved. Eq. if I then return to my /login form, and print the user token, I get:

AnonymousToken(user="anon.", authenticated=true, roles="")

No matter what I seem to do. Any help would be appreciated please: I tried making sure that my sessions are started in the "before" controller: they are.

$app['session']->start();

I should mention that I am running HHVM instead of "vanilla PHP". It should roughly correspond to PHP 5.5 and everything else seems to work.

In advance thank you for your help.

EDIT: it appears to be a problem with HHVM and the version of Silex in use, which I am reporting now to the Silex team. The same code works just fine with php5-fpm.

1
I have exactly the same problem, did you find a solution ? - Macbernie
See my second post. This is a (now known) Silex/HHVM Bug. The problem for me was with the session handler. Using the database session handler allowed me to get this feature working again. - Mauro Colella

1 Answers

1
votes

The issue simply pertains to the native session handler of Silex when used on HHVM.

As a workaround, I recommend using the PdoSessionHandler.

$app['session.db_options'] = array(
    'db_table'      => 'session',
    'db_id_col'     => 'session_id',
    'db_data_col'   => 'session_value',
    'db_time_col'   => 'session_time',
);

$app['session.storage.handler'] = $app->share(function () use ($app) {
    return new PdoSessionHandler(
        $app['db']->getWrappedConnection(),
        $app['session.db_options'],
        $app['session.storage.options']
    );
});

The complete code is available here: http://silex.sensiolabs.org/doc/cookbook/session_storage.html