Skip to content

Instantly share code, notes, and snippets.

@srsbiz
Created January 5, 2016 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srsbiz/38c8ac58c4774906e80e to your computer and use it in GitHub Desktop.
Save srsbiz/38c8ac58c4774906e80e to your computer and use it in GitHub Desktop.
<?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