{"action":"created","issue":{"url":"https://api.github.com/repos/silexphp/Silex/issues/1240","repository_url":"https://api.github.com/repos/silexphp/Silex","labels_url":"https://api.github.com/repos/silexphp/Silex/issues/1240/labels{/name}","comments_url":"https://api.github.com/repos/silexphp/Silex/issues/1240/comments","events_url":"https://api.github.com/repos/silexphp/Silex/issues/1240/events","html_url":"https://github.com/silexphp/Silex/issues/1240","id":104415720,"number":1240,"title":"Support for SimplePreAuthenticator and SimpleFormAuthenticator","user":{"login":"henrikbjorn","id":19725,"avatar_url":"https://avatars.githubusercontent.com/u/19725?v=3","gravatar_id":"","url":"https://api.github.com/users/henrikbjorn","html_url":"https://github.com/henrikbjorn","followers_url":"https://api.github.com/users/henrikbjorn/followers","following_url":"https://api.github.com/users/henrikbjorn/following{/other_user}","gists_url":"https://api.github.com/users/henrikbjorn/gists{/gist_id}","starred_url":"https://api.github.com/users/henrikbjorn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/henrikbjorn/subscriptions","organizations_url":"https://api.github.com/users/henrikbjorn/orgs","repos_url":"https://api.github.com/users/henrikbjorn/repos","events_url":"https://api.github.com/users/henrikbjorn/events{/privacy}","received_events_url":"https://api.github.com/users/henrikbjorn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-09-02T07:09:29Z","updated_at":"2016-05-03T15:27:39Z","closed_at":null,"body":"This seems to be missing from SecurityServiceProvider. Not sure about the best implementation of this.\r\nBut so far i am using this in my projects:\r\n\r\n``` php\r\n        $app['security.authentication.simple_handler._proto'] = $app->protect(function ($name, $options) use ($app) {\r\n            return $app->share(function () use ($app, $name, $options) {\r\n                return new SimpleAuthenticationHandler(\r\n                    $app['security.authentication.authenticator.'.$name],\r\n                    $app['security.authentication.success_handler.'.$name],\r\n                    $app['security.authentication.failure_handler.'.$name],\r\n                    $app['logger']\r\n                );\r\n            });\r\n        });\r\n\r\n        $app['security.authentication_listener.simple_pre._proto'] = $app->protect(function ($name, $options) use ($app) {\r\n            return $app->share(function () use ($app, $name, $options) {\r\n                if (!isset($app['security.authentication.simple_handler.'.$name])) {\r\n                    $app['security.authentication.simple_handler.'.$name] = $app['security.authentication.simple_handler._proto']($name, $options);\r\n                }\r\n\r\n                if (!isset($app['security.authentication.success_handler.'.$name])) {\r\n                    $app['security.authentication.success_handler.'.$name] = $app['security.authentication.success_handler._proto']($name, $options);\r\n                }\r\n\r\n                if (!isset($app['security.authentication.failure_handler.'.$name])) {\r\n                    $app['security.authentication.failure_handler.'.$name] = $app['security.authentication.failure_handler._proto']($name, $options);\r\n                }\r\n\r\n                return new SimplePreAuthenticationListener(\r\n                    $app['security.token_storage'],\r\n                    $app['security.authentication_manager'],\r\n                    $name,\r\n                    $app['security.authentication.authenticator.'.$name],\r\n                    $app['logger'],\r\n                    $app['dispatcher']\r\n                );\r\n            });\r\n        });\r\n\r\n        $app['security.authentication_provider.simple_pre._proto'] = $app->protect(function ($name) use ($app) {\r\n            return $app->share(function () use ($app, $name) {\r\n                return new SimpleAuthenticationProvider(\r\n                    $app['security.authentication.authenticator.'.$name],\r\n                    $app['security.user_provider.'.$name],\r\n                    $name\r\n                );\r\n            });\r\n        });\r\n\r\n        $app['security.authentication_listener.factory.simple_pre'] = $app->protect(function ($name, $options) use ($app) {\r\n            if (!isset($app['security.entry_point.'.$name.'.simple_pre'])) {\r\n                $app['security.entry_point.'.$name.'.simple_pre'] = $app['security.entry_point.http._proto']($name, $options);\r\n            }\r\n\r\n            if (!isset($app['security.authentication.authenticator.'.$name])) {\r\n                $app['security.authentication.authenticator.'.$name] = $app['security.authentication.authenticator.'.$name.'._proto']($name, $options);\r\n            }\r\n\r\n            if (!isset($app['security.authentication_listener.'.$name.'.simple_pre'])) {\r\n                $app['security.authentication_listener.'.$name.'.simple_pre'] = $app['security.authentication_listener.simple_pre._proto']($name, $options);\r\n            }\r\n\r\n            if (!isset($app['security.authentication_provider.'.$name.'.simple_pre'])) {\r\n                $app['security.authentication_provider.'.$name.'.simple_pre'] = $app['security.authentication_provider.simple_pre._proto']($name);\r\n            }\r\n\r\n            return array(\r\n                'security.authentication_provider.'.$name.'.simple_pre',\r\n                'security.authentication_listener.'.$name.'.simple_pre',\r\n                'security.entry_point.'.$name.'.simple_pre',\r\n                'form',\r\n            );\r\n        });\r\n\r\n        $app['security.authentication.simple_handler._proto'] = $app->protect(function ($name, $options) use ($app) {\r\n            return $app->share(function () use ($app, $name, $options) {\r\n                return new SimpleAuthenticationHandler(\r\n                    $app['security.authentication.authenticator.'.$name],\r\n                    $app['security.authentication.success_handler.'.$name],\r\n                    $app['security.authentication.failure_handler.'.$name],\r\n                    $app['logger']\r\n                );\r\n            });\r\n        });\r\n```\r\n\r\nWith a security config like:\r\n\r\n``` php\r\n        $app['security.firewalls'] = [\r\n            'exchange' => [\r\n                'pattern' => '/authenticate',\r\n                'stateless' => true,\r\n                'simple_pre' => true,\r\n                'users' => $app->share(function ($app) {\r\n                    return $app['user_provider'];\r\n                }),\r\n            ],\r\n            'api' => [\r\n                'pattern' => '/api',\r\n                'stateless' => true,\r\n                'simple_pre' => true,\r\n                'users' => $app->share(function ($app) {\r\n                    return $app['user_provider'];\r\n                }),\r\n            ],\r\n        ];\r\n```\r\n\r\nIt is needed to add these services to integrate an Authenticator\r\n\r\n``` php\r\n        $app['security.authentication.authenticator.exchange._proto'] = $app->protect(function ($name, $options) use ($app) {\r\n            return $app->share(function () use ($app, $name, $options) {\r\n                return new UsernamePasswordAuthenticator(\r\n                    $app['security.user_checker'],\r\n                    $app['security.password_encoder'],\r\n                    $app['antenna.coder']\r\n                );\r\n            });\r\n        });\r\n\r\n        $app['security.authentication.authenticator.api._proto'] = $app->protect(function ($name, $options) use ($app) {\r\n            return $app->share(function () use ($app, $name, $options) {\r\n                return new TokenAuthenticator($app['security.user_checker'], $app['antenna.coder']);\r\n            });\r\n        });\r\n```\r\n\r\n(the Authenticators implemented here is from github.com/flint/antenna)"},"comment":{"url":"https://api.github.com/repos/silexphp/Silex/issues/comments/216565020","html_url":"https://github.com/silexphp/Silex/issues/1240#issuecomment-216565020","issue_url":"https://api.github.com/repos/silexphp/Silex/issues/1240","id":216565020,"user":{"login":"ragboyjr","id":1975857,"avatar_url":"https://avatars.githubusercontent.com/u/1975857?v=3","gravatar_id":"","url":"https://api.github.com/users/ragboyjr","html_url":"https://github.com/ragboyjr","followers_url":"https://api.github.com/users/ragboyjr/followers","following_url":"https://api.github.com/users/ragboyjr/following{/other_user}","gists_url":"https://api.github.com/users/ragboyjr/gists{/gist_id}","starred_url":"https://api.github.com/users/ragboyjr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ragboyjr/subscriptions","organizations_url":"https://api.github.com/users/ragboyjr/orgs","repos_url":"https://api.github.com/users/ragboyjr/repos","events_url":"https://api.github.com/users/ragboyjr/events{/privacy}","received_events_url":"https://api.github.com/users/ragboyjr/received_events","type":"User","site_admin":false},"created_at":"2016-05-03T15:27:39Z","updated_at":"2016-05-03T15:27:39Z","body":"@henrikbjorn, @fabpot, can we close this now that we have Guard support from #1260?"}}