Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
class AutoLoginServiceProvider implements \Silex\ServiceProviderInterface {
public function boot(\Silex\Application $app) {
if (!isset($app['security'])) {
throw new \LogicException('You must register the SecurityServiceProvider to use the AutoLoginServiceProvider');
}
}
public function register(\Silex\Application $app) {
$app['security.authentication_listener.factory.auto_login'] = $app->protect(function ($name, $options) use ($app) {
if (!isset($app['security.authentication_listener.'.$name.'.auto_login'])) {
$app['security.authentication_listener.'.$name.'.auto_login'] = $app->share(function() use($app, $options, $name){
return new \Jmikola\AutoLogin\Http\Firewall\AutoLoginListener(
$app['security'],
$app['security.authentication_manager'],
$name,
isset($options['request_param']) ? $options['request_param'] : '_token',
$app['logger'],
$app['dispatcher'],
$options
);
});
}
if (!isset($app['security.authentication_provider.'.$name.'.auto_login'])) {
$app['security.authentication_provider.'.$name.'.auto_login'] = $app->share(function() use($app, $options, $name){
if (isset($options['user_provider'])) {
$provider = $options['user_provider'];
} else {
$provider = $app['security.firewalls'][$name]['users'];
if ($provider instanceof \Closure) {
$provider = $provider($app);
}
}
return new \Jmikola\AutoLogin\Authentication\Provider\AutoLoginProvider(
$provider,
$app['security.user_checker'],
$name
);
});
}
return array(
'security.authentication_provider.'.$name.'.auto_login',
'security.authentication_listener.'.$name.'.auto_login',
null, // entry point
'pre_auth'
);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.